简单应用程序崩溃?

4

我有一个非常简单的基于窗口的应用程序,我只是将导航视图控制器作为窗口的根视图控制器,并且它崩溃了。这是我在模板项目中改变的唯一事情:

@interface AppDelegate : NSObject <UIApplicationDelegate> {
    UINavigationController *navigationController;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    navigationController = [[UINavigationController alloc] init];


    [[self window] setRootViewController:navigationController];
    [self.window makeKeyAndVisible];
    return YES;
}

它崩溃并显示以下信息:
2011-05-26 20:18:57.194 ZebraSDKTest[5560:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UICustomObject 0x8b3d760> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navigationController.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00dbf5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00f13313 objc_exception_throw + 44
    2   CoreFoundation                      0x00dbf4e1 -[NSException raise] + 17
    3   Foundation                          0x00791677 _NSSetUsingKeyValueSetter + 135
    4   Foundation                          0x007915e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
    5   UIKit                               0x0020d30c -[UIRuntimeOutletConnection connect] + 112
    6   CoreFoundation                      0x00d358cf -[NSArray makeObjectsPerformSelector:] + 239
    7   UIKit                               0x0020bd23 -[UINib instantiateWithOwner:options:] + 1041
    8   UIKit                               0x0020dab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    9   UIKit                               0x0001317a -[UIApplication _loadMainNibFile] + 172
    10  UIKit                               0x00013cf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
    11  UIKit                               0x0001e617 -[UIApplication handleEvent:withNewEvent:] + 1533
    12  UIKit                           

0x00016abf -[UIApplication sendEvent:] + 71
13  UIKit                               0x0001bf2e _UIApplicationHandleEvent + 7576
14  GraphicsServices                    0x00ff8992 PurpleEventCallback + 1550
15  CoreFoundation                      0x00da0944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16  CoreFoundation                      0x00d00cf7 __CFRunLoopDoSource1 + 215
17  CoreFoundation                      0x00cfdf83 __CFRunLoopRun + 979
18  CoreFoundation                      0x00cfd840 CFRunLoopRunSpecific + 208
19  CoreFoundation                      0x00cfd761 CFRunLoopRunInMode + 97
20  UIKit                               0x000137d2 -[UIApplication _run] + 623
21  UIKit                               0x0001fc93 UIApplicationMain + 1160
22  ZebraSDKTest                        0x00002549 main + 121
23  ZebraSDKTest                        0x000024c5 start + 53

)

2个回答

4

看起来您在某个nib文件中有一个连接到以前存在的UINavigationController IBOutlet。

从MainWindow.xib开始检查是否存在这样的连接。


1
尝试从设备或模拟器中删除该应用程序。 - Matthias Bauch
Xcode 菜单中,选择 Product > Clean。完成后,构建你的项目并运行它。 - Deepak Danduprolu
我刚刚下载并运行了你的应用程序,没有任何问题,所以我不确定问题出在哪里。代码似乎没问题,xib文件也是如此。我想这可能是你的模拟器或Xcode的内部问题。我建议你采纳@Deepak的建议进行清理。如果这样还不行,退出Xcode和模拟器,然后重新打开看看是否可以解决问题。 - justin
还是不行。但是我刚刚创建了一个新项目,重新开始了。不知道为什么会这样... - sumderungHAY
我也遇到了同样的问题。我只是移除了所有的插座连接并重新创建 IBOutlet;现在它对我来说正常工作了。 - akrant_iOSDeveloper
显示剩余2条评论

2

我遇到了这个问题,只在模拟器上出现,但在设备上运行正常。

我尝试了清理项目、重启Xcode、调试、清空模拟器数据等方法,但都没有解决问题。

最后,通过卸载模拟器中的应用并重新安装解决了问题。不知道为什么这样可以解决,但问题得到了解决!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接