0

我正在学习 Swift,我在 DesignCode 中开设课程,现在我正在尝试创建一个应用程序来改进我所学的内容。

这就是我所做的:

  • 我创建了 UIViewController 并对 UITableViewController 执行 segue;

  • 在我嵌入导航栏的 UITableViewController 中,我创建了一个“返回”栏按钮项;

  • 我将这个“Back”链接到退出,通过“Spring”执行一个segue来放松。

当我单击此按钮时,我收到以下错误:

2015-06-04 15:32:08.662 Vitrine[2883:67901] *** Assertion failure in -[UIStoryboardUnwindSegueTemplate _perform:], /SourceCache/UIKit_Sim/UIKit-3347.44/UIStoryboardUnwindSegueTemplate.m:78
2015-06-04 15:32:08.676 Vitrine[2883:67901] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not find a view controller to execute unwinding for <UINavigationController: 0x7ae41540>'
*** First throw call stack:
(
    0   CoreFoundation                      0x0154d746 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x02f4ea97 objc_exception_throw + 44
    2   CoreFoundation                      0x0154d5da +[NSException raise:format:arguments:] + 138
    3   Foundation                          0x019c3720 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
    4   UIKit                               0x0253d3b4 -[UIStoryboardUnwindSegueTemplate _perform:] + 387
    5   UIKit                               0x0237c313 -[UIStoryboardSegueTemplate perform:] + 116
    6   libobjc.A.dylib                     0x02f647cd -[NSObject performSelector:withObject:withObject:] + 84
    7   UIKit                               0x01d72a90 -[UIApplication sendAction:to:from:forEvent:] + 99
    8   UIKit                               0x020f8bba -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 139
    9   libobjc.A.dylib                     0x02f647cd -[NSObject performSelector:withObject:withObject:] + 84
    10  UIKit                               0x01d72a90 -[UIApplication sendAction:to:from:forEvent:] + 99
    11  UIKit                               0x01d72a22 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    12  UIKit                               0x01eb318a -[UIControl sendAction:to:forEvent:] + 69
    13  UIKit                               0x01eb35a7 -[UIControl _sendActionsForEvents:withEvent:] + 598
    14  UIKit                               0x01eb2811 -[UIControl touchesEnded:withEvent:] + 660
    15  UIKit                               0x01dcacfa -[UIWindow _sendTouchesForEvent:] + 874
    16  UIKit                               0x01dcb7d6 -[UIWindow sendEvent:] + 792
    17  UIKit                               0x01d896d1 -[UIApplication sendEvent:] + 242
    18  UIKit                               0x01d99b08 _UIApplicationHandleEventFromQueueEvent + 21484
    19  UIKit                               0x01d6d337 _UIApplicationHandleEventQueue + 2300
    20  CoreFoundation                      0x0146f06f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    21  CoreFoundation                      0x01464b7d __CFRunLoopDoSources0 + 253
    22  CoreFoundation                      0x014640d8 __CFRunLoopRun + 952
    23  CoreFoundation                      0x01463a5b CFRunLoopRunSpecific + 443
    24  CoreFoundation                      0x0146388b CFRunLoopRunInMode + 123
    25  GraphicsServices                    0x050c62c9 GSEventRunModal + 192
    26  GraphicsServices                    0x050c6106 GSEventRun + 104
    27  UIKit                               0x01d71106 UIApplicationMain + 1526
    28  Vitrine                             0x00076cd4 main + 180
    29  libdyld.dylib                       0x0366bac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

问候, 迪奥戈·阿马拉尔

4

2 回答 2

0

要添加标准导航和导航栏,您应该使用UINavigationController. 将UINavigationController“包装”导航流(堆栈)中的其他视图,因此您无需UINavigationBar在任何视图上添加任何视图。

如果正确实施Back,则由UINavigationController.

在此处输入图像描述

左箭头:初始视图控制器应指向UINavigationController

第一个segue:根视图控制器=将显示的第一个视图控制器。

第二段:show。触发一个showsegue,UINavigationController 将推送下一个视图。将显示一个后退链接用于后退导航。

您可以使用show segue 链接任意数量的视图,如果需要,您可以show从同一个视图控制器获得多个 segue。

更新:

如果你真的想出于不同的原因使用 unwind segues,这里有一个关于它们如何工作的很好的解释:

Unwind segues 有什么用,你如何使用它们?

于 2015-06-04T19:11:22.210 回答
0

您必须在您想要返回的视图中创建一个 IBAction,如下所示:

@IBAction func back(segue:UIStoryboardSegue) {
        //no code here, unless you want to do something when exiting
    }

然后,在您要退出的视图中,将您的链接barButtonItem到出口(IBAction 应该出现在那里)。

于 2015-06-04T19:23:38.663 回答