【问题标题】:Need help in navigating view controllers在导航视图控制器方面需要帮助
【发布时间】:2013-08-24 17:58:27
【问题描述】:

我正在开发一个小型 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 新手。 如果你们中的任何人知道如何以更好的方式做到这一点,那将是很高兴听到它!

【问题讨论】:

  • 你想设置类似导航推送弹出的动画吗?
  • @iPatel 他没有使用 navigationController
  • 他还说我卡住了,我没有使用任何导航控制器,请阅读
  • @NitinGohel- 是的,兄弟。你是对的:)
  • @Gaurav 你必须对给出你问题答案的人的答案做出回应。

标签: ios


【解决方案1】:

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

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

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

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

[self.navigationController popToRootViewControllerAnimated:YES];

【讨论】:

  • 不,我没有使用 navigationController 它的所有视图控制器
【解决方案2】:

如果你想给出推送和弹出动画,那么你必须制作当前视图控制器来制作导航控制器的根控制器。

然后在这之后::

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多