好吧,我没有开始使用Objective C和Xcode - 这是我第二次来这里寻求帮助的一个简单项目 - 令人尴尬!
我的主(Squad)视图控制器加载一个细节(Pilot)视图控制器,后者又加载一个带模态segue的第三个视图控制器(SelectNewPilot)。这很好用。如果按SelectNewPilot(模态)视图上的取消按钮,它将展开到Pilot(详细信息)视图控制器。在Pilot视图控制器中,我有以下代码:
- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
UIViewController *source = [segue sourceViewController];
if([source isKindOfClass:[Mz0SelectNewPilotViewController class]])
{
if ([(Mz0SelectNewPilotViewController *)source pilot] == nil)
{
NSLog(@"We cancelled selecting a new pilot");
[self performSegueWithIdentifier:@"Unwind" sender:self];
}
else
{
NSLog(@"We selected %@", [[(Mz0SelectNewPilotViewController *)source pilot] name]);
}
}
}
因此,如果SelectNewPilot(模态)控制器中没有选择任何内容(即它被取消),则Pilot控制器会自动进一步退回到Squad(主)控制器。这会产生以下错误:
2014-03-13 00:45:07.578 Squad Builder[3149:70b] *** Assertion failure in -[UINavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-2935.120.3/UINavigationController.m:4886
2014-03-13 00:45:07.581 Squad Builder[3149:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'
*** First throw call stack:
(
0 CoreFoundation 0x01b629e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018e28e5 objc_exception_throw + 44
2 CoreFoundation 0x01b62848 +[NSException raise:format:arguments:] + 136
3 Foundation 0x014c20de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x006edbe0 -[UINavigationController popToViewController:transition:] + 302
5 UIKit 0x006edaad -[UINavigationController popToViewController:animated:] + 56
6 UIKit 0x006e633f __90-[UINavigationController segueForUnwindingToViewController:fromViewController:identifier:]_block_invoke + 142
7 UIKit 0x00b197ac -[UIStoryboardSegue perform] + 35
8 UIKit 0x00c7d623 -[UIStoryboardUnwindSegueTemplate _perform:] + 554
9 UIKit 0x00b090b7 -[UIStoryboardSegueTemplate perform:] + 115
10 libobjc.A.dylib 0x018f4880 -[NSObject performSelector:withObject:withObject:] + 77
11 UIKit 0x005a67f9 -[UIApplication sendAction:to:from:forEvent:] + 108
12 UIKit 0x008938bf -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 139
13 libobjc.A.dylib 0x018f4880 -[NSObject performSelector:withObject:withObject:] + 77
14 UIKit 0x005a67f9 -[UIApplication sendAction:to:from:forEvent:] + 108
15 UIKit 0x005a6785 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
16 UIKit 0x006a7fe1 -[UIControl sendAction:to:forEvent:] + 66
17 UIKit 0x006a83d6 -[UIControl _sendActionsForEvents:withEvent:] + 577
18 UIKit 0x006a7653 -[UIControl touchesEnded:withEvent:] + 641
19 UIKit 0x005e621d -[UIWindow _sendTouchesForEvent:] + 852
20 UIKit 0x005e6e11 -[UIWindow sendEvent:] + 1117
21 UIKit 0x005b8a32 -[UIApplication sendEvent:] + 242
22 UIKit 0x005a2793 _UIApplicationHandleEventQueue + 11455
23 CoreFoundation 0x01aebf7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
24 CoreFoundation 0x01aeb90b __CFRunLoopDoSources0 + 235
25 CoreFoundation 0x01b089ae __CFRunLoopRun + 910
26 CoreFoundation 0x01b081d3 CFRunLoopRunSpecific + 467
27 CoreFoundation 0x01b07feb CFRunLoopRunInMode + 123
28 GraphicsServices 0x03a175ee GSEventRunModal + 192
29 GraphicsServices 0x03a1742b GSEventRun + 104
30 UIKit 0x005a53db UIApplicationMain + 1225
31 Squad Builder 0x0000a6bd main + 141
32 libdyld.dylib 0x021ad701 start + 1
)
如果我注释掉这条线 [self performSegueWithIdentifier:@“Unwind”sender:self]; 然后它工作正常,你只需按下Pilot控制器上的取消就可以回到Squad控制器。我的问题是当你使用按钮来触发它时,为什么放松segue(从Pilot到Squad)工作,但是当以编程方式调用时(它是相同的展开segue,我只是将一个标识符应用于取消按钮使用的那个)?
小队控制器中的unwindToList方法完成,所以我不确定是什么被调用导致错误。什么使segue试图弹出一些东西?这是故事板中的某个地方吗?
Squad控制器的unwindToList方法如下(两个NSLog输出都出现在错误之前):
- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
NSLog(@"Unwound to Squad");
Mz0PilotViewController *source = [segue sourceViewController];
Mz0Card *pilot = [source pilot];
if ([pilot isKindOfClass:[Mz0Card class]])
{
NSLog(@"Adding new pilot: %@", [pilot name]);
if(![_testData containsObject:pilot])
{
[_testData addObject:pilot];
[self.tableView reloadData];
}
}
NSLog(@"Finished unwinding to Squad");
}
更新:在开始打印输出(然后是最终错误)之前,我刚发现另一个错误:
Unbalanced calls to begin/end appearance transitions for <Mz0SquadViewController: 0x8dc8720>
这是因为它试图放松太快吗?有没有办法告诉它不要从Pilot到Squad放松,直到第一次放松(从SelectNewPilot到Pilot)完成?