@ walle84给出的解决方案非常棒...但不是Unwind Segue解决方案。如果你想使用真正的Unwind Segues,请按照这个步骤进行。
在你FirstViewController.m文件,添加一个-reset:
方法,使您的代码如下所示:
#import "FirstViewController.h"
@interface FirstViewController()
@end
@implementation FirstViewController
-(IBAction)reset:(UIStoryboardSegue *)segue {
//you can do stuff here, if necessary
//popToRootViewControllerAnimated doesn't allow it
NSLog(@"Back to FirstViewController");
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
在你ThirdViewController.m,设置您的-alertView:clickedButtonAtIndex:
方法,使您的代码如下所示:
#import "ThirdViewController.h"
@interface ThirdViewController() <UIAlertViewDelegate>
@end
@implementation ThirdViewController
- (IBAction)buttonPressed:(id)sender {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"MyApp"
message:@"Do you want to reset to FirstViewController?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[message addButtonWithTitle:@"Perform Unwind"];
[message show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[self performSegueWithIdentifier:@"myUnwindSegue" sender:self];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
然后,在你的故事板,选择ThirdViewController
场景,点击Third View Controller
按钮,将其拖动到Exit
按钮(见下图)。弹出窗口会出现。选择其中的Reset:
链接。
完成后,选择您unwind segue
按钮(见下图),并在属性检查器,设置它的名称为“myUnwindSegue”(见下图)。
如果您想了解更多关于放松身心塞格斯,你可以看WWDC 2012会话视频“在您的应用程序采用故事板” [开始在38分钟]。
使用[self.navigationcontroller poptorootviewcontroller]方法 – 2014-09-12 10:22:40
拯救生命。谢谢 – invisibloom 2014-09-12 10:24:28