I have an app that when loads, loads a tab based app whereby all tabs work fine. In the first tab however the view loaded has a whole bunch of buttons. I have written methods of these buttons so when pressed they push a new subview (.xib) and this works fine.
However, when in these new subviews I have a back button which has its own method. I want this button to remove the view and return back to the orignal view. Here is the code from FirstViewController.m.
Bear in mind that this File holds all the code even though it handles different .xib files. basically it pushes FirstView first, then when button is pressed it will push E87view.xib, the code for the .xib is still within the firstviewcontroller file.
-(IBAction) backButtonPressed {
[self showAll];
backButton.hidden = 1;
for (UIView *subview in [self.view subviews]) {
[subview removeFromSuperview];
}
[self showAll];
}
-(IBAction) E87Pressed {
//[self hideAll];
E87view *e87view = [[E87view alloc] initWithNibName:@"E87view" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:e87view animated:YES];
[self.view addSubview:e87view.view];
}
So just to reiterate, when i press the button E87 on the first view that’s loaded FirstView.xib it will push the new view E87view.xib. However when I press the back button on this newly loaded E87view it will access the above function and remove the view but also remove all the setup I had from FirstView.xib essentially leaving me with an empty app.
Hope this makes sense I can ramble a bit.
Regards,
Lewis
Instead of removing every individual subviews, just remove the ViewController from the navigation controller using
And this line is unnecessary