2014-04-21 58 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]; 
相關問題