Reputation: 1277
I am developing one small iOS app, and am facing a problem in navigation of view controllers. This is my code (I got it from the net):
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *)indexPath
{
DetailsViewController *page = [[DetailsViewController alloc] init];
CGRect theFrame = page.view.frame;
theFrame.origin = CGPointMake(self.view.frame.size.width, 0);
page.view.frame = theFrame;
theFrame.origin = CGPointMake(0,0);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2f];
page.view.frame = theFrame;
[UIView commitAnimations];
[self.view addSubview:page.view];
}
By which I can navigate to new view controller. This is working fine but I now need to come back to my original controller upon tapping of a button. This is where I am stuck and I am not using any navigation controllers and am new to iOS. If any of you have an idea of how this can be done in a better way it would be great to hear it!
Upvotes: 0
Views: 100
Reputation: 6427
If you want to give push and pop animation then you have to make current view Controller to make root controller of Navigation Controller.
And then after this ::
A_ViewController
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *)indexPath
{
B_ViewContorller *page = [[DetailsViewController alloc] init];
[self.navigationController pushViewController:page animated:YES];
}
B_ViewController After reaching to B_ViewController and want to back to A_ViewController
Just Use this if you are not using default navigationBar
[self.navigationController popToRootViewControllerAnimated:YES];
One of the advantage to use default navigation Bar that it gives you default back button. I recommended to use Default navigation-bar.
Upvotes: 0
Reputation: 5081
Go to nextview controller used this code..
ViewController * v=[[ViewController alloc]init];
[self.navigationController pushViewController:v animated:YES];
back on privous main view controller used this code
[self.navigationController popToRootViewControllerAnimated:YES];
Upvotes: 1