在视图控制器之间切换

发布于 2024-12-21 22:12:00 字数 1307 浏览 2 评论 0原文

我有三个视图控制器。我使用了 Flipsideproject 模板,然后添加了另一个视图控制器。

第一个视图控制器上有一个按钮可以转到第二个视图控制器。第二个视图控制器上有一个按钮可以返回第一个视图控制器。在第一个和第二个之间切换时,这些按钮始终有效。

第二和第三视图控制器的情况相同。当我尝试在第一到第二到第三之间转移,然后返回到第一时,它不起作用。

(1-->2-->3-->2-/->1) 我画得不好的图表描述了这种情况。

我将所有后退按钮都连接到了后 IBAction,我认为这是问题所在。然后我又做了一个IBAction,但它并没有解决问题。

第一个视图控制器 = MainViewController 第二个 VC = FlipSideViewController 3rd VC = ChooseAlarmSound

这是用于进行 2->1 (这是我认为的问题。它有时有效)

- (IBAction)done:(id)sender 
{ 
   [self.delegate flipsideViewControllerDidFinish:self]; 
} 

这是用于进行 2->3

- (IBAction)chooseSound:(id)sender 
{ 
    ChooseAlarmSound *controller = [[[ChooseAlarmSound alloc] initWithNibName:@"ChooseAlarmSound" bundle:nil] autorelease]; 
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:controller animated:YES]; 
}

这是用于进行 3->2

- (IBAction)goBack:(id)sender 
{ 
    FlipsideViewController *controller = [[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil] autorelease];
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:controller animated:YES]; 
}

I have three view controllers. I used the flipsideproject template and then added another view controller.

There is a button on the first view controller that goes to the second view controller. There is a button on the second view controller that goes back to the first one. When switching between the first and second, those buttons always work.

It is the same situation with the second and third view controller. When I try to transfer between the first to second to third and then back to first, it does not work.

(1-->2-->3-->2-/->1) My poorly drawn diagram depicts the situation.

I had all of the back buttons connected to the back IBAction, which I thought was the problem. I then made another IBAction, but it has not fixed the problem.

1st view controller = MainViewController
2nd VC = FlipSideViewController
3rd VC = ChooseAlarmSound

This is for going 2->1 (this is the problem I think. It sometimes works)

- (IBAction)done:(id)sender 
{ 
   [self.delegate flipsideViewControllerDidFinish:self]; 
} 

This is for going 2->3

- (IBAction)chooseSound:(id)sender 
{ 
    ChooseAlarmSound *controller = [[[ChooseAlarmSound alloc] initWithNibName:@"ChooseAlarmSound" bundle:nil] autorelease]; 
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:controller animated:YES]; 
}

This is for going 3->2

- (IBAction)goBack:(id)sender 
{ 
    FlipsideViewController *controller = [[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil] autorelease];
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:controller animated:YES]; 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆流年 2024-12-28 22:12:00

您使用 modalviewcontroller 展示了您的第三个 VC(从 2 到 3)。但随后您尝试使用另一个 modalVC 返回第二个 VC(从第三个到第二个)。这不会让你回到第二个 VC 的前一个实例。您需要使用 dismissmodalviewcontrolleranimated 方法来执行此操作。有关详细信息,请查看 Apple 网站上的 modalviewcontroller 类参考。

You presented your 3rd VC (going from 2 to 3) using modalviewcontroller. But then you tried to go back to 2nd VC (from 3rd to 2nd) using another modalVC. That will not let you go back to the previous instance of 2nd VC. You need to use dismissmodalviewcontrolleranimated method to do this. Checkout Apple website on modalviewcontroller class reference for detail info on this.

倾`听者〃 2024-12-28 22:12:00

正如 user523234 所建议的,您所需要做的就是调用

[self dismissModalViewControllerAnimated:YES]

第三

- (IBAction)goBack:(id)sender 

个视图控制器的方法,而不是您正在做的事情,即创建第二个视图控制器的另一个实例并呈现它。

它现在不起作用的原因是,当您按下第二个视图控制器中的完成按钮时,它

 - (IBAction)done:(id)sender 
{ 
   [self.delegate flipsideViewControllerDidFinish:self]; 
}

会调用向第二个视图控制器的委托发送消息,而您在从 3- 开始的情况下尚未设置该委托>2。

As suggested by user523234, all you need to do is call

[self dismissModalViewControllerAnimated:YES]

in the

- (IBAction)goBack:(id)sender 

method of the 3rd view controller, instead of what you're doing, which is creating another instance of the 2nd view controller and presenting it.

The reason it's not working now, is because when you press the done button in the 2nd view controller it calls

 - (IBAction)done:(id)sender 
{ 
   [self.delegate flipsideViewControllerDidFinish:self]; 
}

which is sending a message the 2nd view controller's delegate, which you haven't set in the case where you're going from 3->2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文