Hi, I've created a button that when pressed displays a subview which contains a "Back" button. I would like the current view to be dismissed when the Back button is pressed. I have tried in the following way but of course it does not work as the compiler does not recognize CurrentView which is defined inside (
Any advice on how to work around this would be highly appreciated. Also I don't know how to remove the view and therefore I am trying to hide it. Would it work with
?
This is my code:
Code:
IBAction) ShowThisView.
Code:
[CurrentView removeFromSuperview];
This is my code:
Code:
- (IBAction) ShowThisView: (id) sender {
CGRect GridBackground = CGRectMake(0, 0, 320, 380);
UIView *myView = [[UIView alloc] initWithFrame:GridBackground];
myView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myView];
UIButton *BackButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
BackButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
[BackButton setTitle:@"Back" forState:UIControlStateNormal];
BackButton.backgroundColor = [UIColor clearColor];
[BackButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
[BackButton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];}
-(void) goBack {
//Hides the view
[CurrentView setHidden:YES];}