2014-04-21 57 views
0

我试图让我的应用程序从一个视图切换到另一个视图,然后有一个后退按钮。第一步我没有问题,但现在我正在尝试返回到我的主视图控制器。切换到ViewController(在故事板上)

我曾尝试这样的代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil]; 
ViewController *main = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; 
[main setModalPresentationStyle:UIModalPresentationFullScreen]; 
[self presentModalViewController:main animated:YES]; 

而且也:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil]; 
ViewController *mainView = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; 
[mainView setModalPresentationStyle:UIModalPresentationFullScreen]; 
[self presentViewController:mainView animated:YES completion:NULL]; 

但无论方法正常工作。用方法一,我在最后一行得到一个错误'presentModalViewController:animated:' is deprecated: first deprecated in iOS6.0 至于第二种方法,它只是简单的不起作用。

*** First throw call stack: 
(
    0 CoreFoundation      0x0000000101947495 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x00000001016a699e objc_exception_throw + 43 
    2 UIKit        0x000000010070d2b7 +[UIStoryboard storyboardWithName:bundle:] + 542 
    3 Swindler       0x0000000100001827 -[SecondViewController backButton:] + 103 
    4 UIKit        0x0000000100254f06 -[UIApplication sendAction:to:from:forEvent:] + 80 
    5 UIKit        0x0000000100254eb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 
    6 UIKit        0x0000000100331880 -[UIControl _sendActionsForEvents:withEvent:] + 203 
    7 UIKit        0x0000000100330dc0 -[UIControl touchesEnded:withEvent:] + 530 
    8 UIKit        0x000000010028bd05 -[UIWindow _sendTouchesForEvent:] + 701 
    9 UIKit        0x000000010028c6e4 -[UIWindow sendEvent:] + 925 
    10 UIKit        0x000000010026429a -[UIApplication sendEvent:] + 211 
    11 UIKit        0x0000000100251aed _UIApplicationHandleEventQueue + 9579 
    12 CoreFoundation      0x00000001018d6d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    13 CoreFoundation      0x00000001018d65f2 __CFRunLoopDoSources0 + 242 
    14 CoreFoundation      0x00000001018f246f __CFRunLoopRun + 767 
    15 CoreFoundation      0x00000001018f1d83 CFRunLoopRunSpecific + 467 
    16 GraphicsServices     0x0000000103abef04 GSEventRunModal + 161 
    17 UIKit        0x0000000100253e33 UIApplicationMain + 1010 
    18 Swindler       0x0000000100001e43 main + 115 
    19 libdyld.dylib      0x0000000101fdf5fd start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

任何帮助深表感谢:我热我的后退按钮它崩溃,我可以尽快加载应用程序,但!

回答

0

如果要备份按钮,而不是呈现视图控制器使用push方法,以便它会给你后退导航按钮自动

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

别人的故事板中添加的UIBarButtonItem在你的第二个视图控制器手动,并在该按钮目标方法调用

[self dismissViewControllerAnimated:YES completion:nil]; 
相关问题