更改ViewController的名称会导致应用崩溃?

时间:2011-06-28 22:23:17

标签: iphone xcode cocoa-touch ios4 uiviewcontroller

我使用iOS SDK 4.3在XCode(4.0)中创建了一个基于View的新iPhone应用程序。然后我将ViewController的名称从MyProjectNameViewController更改为LoginViewController。我还用MyProjectNameViewController替换了LoginViewController找到的每个实例,并且我已经仔细检查了界面构建器中的所有链接。

然而,当我尝试运行应用程序时,它崩溃了:

2011-06-29 10:21:36.927 Monitoring[12580:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<LoginViewController 0x4b26bf0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key password.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00dc05a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00f14313 objc_exception_throw + 44
    2   CoreFoundation                      0x00dc04e1 -[NSException raise] + 17
    3   Foundation                          0x00792677 _NSSetUsingKeyValueSetter + 135
    4   Foundation                          0x007925e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
    5   UIKit                               0x0020e30c -[UIRuntimeOutletConnection connect] + 112
    6   CoreFoundation                      0x00d368cf -[NSArray makeObjectsPerformSelector:] + 239
    7   UIKit                               0x0020cd23 -[UINib instantiateWithOwner:options:] + 1041
    8   UIKit                               0x0020eab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    9   UIKit                               0x000c4628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
    10  UIKit                               0x000c2134 -[UIViewController loadView] + 120
    11  UIKit                               0x000c200e -[UIViewController view] + 56
    12  UIKit                               0x00035d42 -[UIWindow addRootViewControllerViewIfPossible] + 51
    13  MyProjectName                       0x000022c7 -[MyProjectNameAppDelegate application:didFinishLaunchingWithOptions:] + 135
    14  UIKit                               0x00012c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    15  UIKit                               0x00014d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    16  UIKit                               0x0001f617 -[UIApplication handleEvent:withNewEvent:] + 1533
    17  UIKit                               0x00017abf -[UIApplication sendEvent:] + 71
    18  UIKit                               0x0001cf2e _UIApplicationHandleEvent + 7576
    19  GraphicsServices                    0x00ff9992 PurpleEventCallback + 1550
    20  CoreFoundation                      0x00da1944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    21  CoreFoundation                      0x00d01cf7 __CFRunLoopDoSource1 + 215
    22  CoreFoundation                      0x00cfef83 __CFRunLoopRun + 979
    23  CoreFoundation                      0x00cfe840 CFRunLoopRunSpecific + 208
    24  CoreFoundation                      0x00cfe761 CFRunLoopRunInMode + 97
    25  UIKit                               0x000147d2 -[UIApplication _run] + 623
    26  UIKit                               0x00020c93 UIApplicationMain + 1160
    27  MyProjectName                       0x00002209 main + 121
    28  MyProjectName                       0x00002185 start + 53

我需要做些什么来解决这个问题?

5 个答案:

答案 0 :(得分:3)

您是否还重命名了nibs / xibs中的类?

错误消息告诉您某些内容需要通过KVC访问password,并且调用它的对象(LoginViewController)不提供对password的KVC兼容访问。你是否使用了password getter / setters?

答案 1 :(得分:3)

原来我需要从iPhone模拟器中删除该应用程序并再次加载它。不应该自动这样做???

答案 2 :(得分:1)

我建议您执行Build / Clean All Targets,删除项目中的/ Build /目录,然后重新运行该项目。如果它仍然崩溃,那么你一定错过了什么。

答案 3 :(得分:0)

你的出口格式不正确。笔尖正在寻找将“密码”绑定到的东西,但控制器中没有相应的属性。

答案 4 :(得分:-1)

得到这个: 1)选择要更改的名称: MyProjectNameViewController 2)编辑 - &gt;重构,填写&#34; LoginViewController &#34; 就是这样。但要注意,如果在设置与之前的视图控制器相同的情况下,可以手动更改storyboardID。