0

我在情节提要中有一个应用程序,并通过情节提要本身的推送操作建立连接second view controller(不使用编码)。

first view controller有没有什么方法可以在不编写任何代码和使用情节提要的情况下弹出?

注意:通过使用navigation controller 我们将有back按钮,但是如果在第二个视图控制器中创建了一个按钮,并且当我们点击该按钮时,我们应该弹出到第一个视图控制器。

4

4 回答 4

1

故事板不提供无需编码即可从 segue 返回的方法,但这可以通过以下代码轻松完成:

[self.navigationController popToRootViewControllerAnimated:YES];
于 2013-08-06T10:51:26.447 回答
0

A solution that involves writing code once but can be used afterwards in your storyboards as a segue without further implementations would be some kind of PopSegue as subclass of a UIStoryboardSegue.

@interface PopSegue : UIStoryboardSegue

Overwrite the -perform method as follows.

@implementation PopSegue

- (void)perform
{
    [[self.sourceViewController navigationController] popViewControllerAnimated:YES];
}

@end

Use a custom segue for back-navigation and specify the PopSegue class.

于 2013-08-06T14:27:16.020 回答
0

Storyboards 没有为 popViewController 提供“无代码”的方式,你需要自己实现。

如果你想弹出到第一个 viewController 你需要使用:

[self.navigationController popToRootViewControllerAnimated:YES];
于 2013-08-06T10:58:15.180 回答
0

UnwindSegue从 iOS6 开始,您也可以使用 an ,尽管它确实需要一些代码)* 用于推送 segues。有关 的一个很好的解释UnwindSegues,请参阅SO 帖子,向下滚动到“In a Nutshell”

)*具体来说,你需要一个放松动作,例如

- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
于 2013-08-06T12:33:35.233 回答