@ 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