应用程序为此视图控制器中不存在的变量抛出NSException?

时间:2014-04-23 04:17:50

标签: xcode nsexception

问题:

当我尝试启动解决方案提交视图控制器时,我的应用程序已经开始崩溃,它会引发以下异常,该异常引用先前版本的变量" projectTitleTextField"已被" projectTitleSearchBar替换。"我不明白为什么它会抛出异常,因为我用搜索栏替换了变量和链接对象,然后清理/构建了项目。请帮助,谢谢。

抛出异常:

2014-04-22 23:51:50.515 AbleConnections[11005:60b] 
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: 
'[<ABLSolutionSubmittalViewController 0x9952510> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key projectTitleTextField.'
*** First throw call stack:
(
    0   CoreFoundation                      0x018091e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x015748e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01898fe1 -[NSException raise] + 17
    3   Foundation                          0x01234d9e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
    4   Foundation                          0x011a11d7 _NSSetUsingKeyValueSetter + 88
    5   Foundation                          0x011a0731 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    6   Foundation                          0x01202b0a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    7   UIKit                               0x004eb1f4 -[UIRuntimeOutletConnection connect] + 106
    8   libobjc.A.dylib                     0x015867de -[NSObject performSelector:] + 62
    9   CoreFoundation                      0x0180476a -[NSArray makeObjectsPerformSelector:] + 314
    10  UIKit                               0x004e9d4d -[UINib instantiateWithOwner:options:] + 1417
    11  UIKit                               0x003526f5 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    12  UIKit                               0x00352e9d -[UIViewController loadView] + 302
    13  UIKit                               0x003530d3 -[UIViewController loadViewIfRequired] + 78
    14  UIKit                               0x00379345 -[UINavigationController _layoutViewController:] + 39
    15  UIKit                               0x0037985b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
    16  UIKit                               0x00379953 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
    17  UIKit                               0x0037a8cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
    18  UIKit                               0x0037b4e9 -[UINavigationController __viewWillLayoutSubviews] + 57
    19  UIKit                               0x004bc0d1 -[UILayoutContainerView layoutSubviews] + 213
    20  UIKit                               0x002a3964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    21  libobjc.A.dylib                     0x0158682b -[NSObject performSelector:withObject:] + 70
    22  QuartzCore                          0x03c6045a -[CALayer layoutSublayers] + 148
    23  QuartzCore                          0x03c54244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    24  QuartzCore                          0x03c540b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    25  QuartzCore                          0x03bba7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    26  QuartzCore                          0x03bbbb85 _ZN2CA11Transaction6commitEv + 393
    27  QuartzCore                          0x03bbc258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    28  CoreFoundation                      0x017d136e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    29  CoreFoundation                      0x017d12bf __CFRunLoopDoObservers + 399
    30  CoreFoundation                      0x017af254 __CFRunLoopRun + 1076
    31  CoreFoundation                      0x017ae9d3 CFRunLoopRunSpecific + 467
    32  CoreFoundation                      0x017ae7eb CFRunLoopRunInMode + 123
    33  GraphicsServices                    0x037e95ee GSEventRunModal + 192
    34  GraphicsServices                    0x037e942b GSEventRun + 104
    35  UIKit                               0x00234f9b UIApplicationMain + 1225
    36  AbleConnections                     0x000047bd main + 141
    37  libdyld.dylib                       0x01e3c701 start + 1
    38  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

ABLSolutionSubmittalViewController类的代码:

// ABLSolutionSubmittalViewController.m
// AbleConnections
// Created by Padft12Laws2Liv on 4/21/14.
// Copyright (c) 2014 ABLE LLC. All rights reserved.

#import "ABLSolutionSubmittalViewController.h"

@interface ABLSolutionSubmittalViewController ()

@property (weak, nonatomic) IBOutlet UISearchBar *projectTitleSearchBar;
//In previous version ^this line read UITextField *projectTitleTextField;
@property (weak, nonatomic) IBOutlet UITextField *countryTextField;
@property (weak, nonatomic) IBOutlet UITextField *solutionTitleTextField;
@property (weak, nonatomic) IBOutlet UITextView *solutionDescriptionTextView;
@property (weak, nonatomic) IBOutlet UITextView *requiredResourcesTextView;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;

@end

@implementation ABLSolutionSubmittalViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (sender != self.saveButton) return;
    if (self.solutionTitleTextField.text.length > 0) {
        self.solutionSubmission = [[ABLSolutionSubmission alloc] init];
        self.solutionSubmission.PROJECT_TITLE = self.projectTitleSearchBar.text;
        self.solutionSubmission.COUNTRY_OF_ORIGIN = self.countryTextField.text;
        self.solutionSubmission.SOLUTION_TITLE = self.solutionTitleTextField.text;
        self.solutionSubmission.solutionDescription = self.solutionDescriptionTextView.text;
        self.solutionSubmission.requiredResources = self.requiredResourcesTextView.text;
    }
}

@end

1 个答案:

答案 0 :(得分:2)

签入xib projectTitleTextField是否与某人相关联。如果它在那里那么应该有警告,所以请删除它。干净并建立项目。也尝试从模拟器中删除应用程序。