需要帮助导航视图控制器

时间:2013-08-23 13:18:05

标签: ios

我正在开发一个小型iOS应用,并且在视图控制器的导航中遇到问题。 这是我的代码(我是从网上得到的):

- (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];
 }

我可以通过它导航到新的视图控制器。这工作正常但我现在需要在点击按钮时回到原来的控制器。这是我被卡住的地方,我没有使用任何导航控制器,我是iOS新手。 如果你们中的任何一个人知道如何以更好的方式做到这一点,那么听到它会很棒!

2 个答案:

答案 0 :(得分:1)

转到nextview控制器使用此代码..

ViewController * v=[[ViewController alloc]init];

[self.navigationController pushViewController:v animated:YES];

返回私有主视图控制器使用此代码

[self.navigationController popToRootViewControllerAnimated:YES];

答案 1 :(得分:0)

如果你想提供推送和流行动画,那么你必须使当前视图控制器成为导航控制器的根控制器。

然后在此之后::

<强> A_ViewController

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:       (NSIndexPath *)indexPath
{
    B_ViewContorller *page = [[DetailsViewController alloc] init];
    [self.navigationController pushViewController:page animated:YES];
}

<强> B_ViewController 到达B_ViewController后想要回到A_ViewController

如果您没有使用默认导航栏,请使用此选项

[self.navigationController popToRootViewControllerAnimated:YES];

使用默认导航栏的一个优点是它为您提供了默认的后退按钮。我建议使用默认导航栏。

相关问题