我试图使我的应用程序从一种视图切换到另一种,然后具有一个后退按钮。 第一步没什么麻烦,但是现在我想回到主视图控制器。

我已经试过这段代码:

1个

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

并且:

2

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了一个错误'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) 

任何帮助深表感谢!

===============>>#1 票数:0 已采纳

如果您想要后退按钮,则无需显示视图控制器,而应使用push方法,这样它将自动为您提供后退导航按钮

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

否则,将UIBarbuttonItem手动添加到情节提要中的第二个视图控制器中,并在该按钮目标方法调用中添加

[self dismissViewControllerAnimated:YES completion:nil];

  ask by user3555248 translate from so

未解决问题?本站智能推荐: