2016-03-27 4 views
0

Ich drücke auf CONTROL und ziehe das UIImageView und UILabel, das in AppView.xib ist, in meine Codedatei namens "AppView.h". Bevor ich die beiden UI-Widgets anschließe, lief alles gut. Ich möchte die Gründe für den Absturz wissen. Vielen Dank für Ihre Antworten. @propertyNachdem ich den UIVIEw an meinen Code angeschlossen habe, ist er abgestürzt, warum?

Der Code wie folgt:

#import <UIKit/UIKit.h> 
@interface AppView : UIView 

@property (weak, nonatomic) IBOutlet UIImageView *icon; 

@property (weak, nonatomic) IBOutlet UILabel *name; 

+ (id)AppViewWithIcon:(NSString *)icon Name:(NSString *)name; 
@end 

#import "AppView.h" 
@implementation AppView 

+ (id)AppViewWithIcon:(NSString *)icon Name:(NSString *)name{ 
    AppView *view = [[NSBundle mainBundle] loadNibNamed:@"AppView" owner:nil options:nil][0]; 
    NSLog(@"%@",view); 
    return view; 

} 

die Fehler, wie folgend:

1.Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP,subcode=0X0) 
2.2016-03-27 18:53:36.804 05-九宫格[4302:283744] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x7fca52c1a1c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key icon.' 

*** First throw call stack: 
(
0 CoreFoundation      0x0000000101630d85 __exceptionPreprocess + 165 
1 libobjc.A.dylib      0x00000001010a4deb objc_exception_throw + 48 
2 CoreFoundation      0x00000001016309c9 -[NSException raise] + 9 
3 Foundation       0x0000000100c6f19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 
4 UIKit        0x0000000101db07fb -[UIRuntimeOutletConnection connect] + 109 
5 CoreFoundation      0x000000010156a890 -[NSArray makeObjectsPerformSelector:] + 224 
6 UIKit        0x0000000101daf1de -[UINib instantiateWithOwner:options:] + 1864 
7 UIKit        0x0000000101db1415 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 223 
8 05-九宫格      0x0000000100ba1490 +[AppView AppViewWithIcon:Name:] + 160 
9 05-九宫格      0x0000000100ba0cae -[ViewController viewDidLoad] + 206 
10 UIKit        0x0000000101b81984 -[UIViewController loadViewIfRequired] + 1198 
11 UIKit        0x0000000101b81cd3 -[UIViewController view] + 27 
12 UIKit        0x0000000101a57fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61 
13 UIKit        0x0000000101a5869d -[UIWindow _setHidden:forced:] + 282 
14 UIKit        0x0000000101a6a180 -[UIWindow makeKeyAndVisible] + 42 
15 UIKit        0x00000001019deed9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 
16 UIKit        0x00000001019e5568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769 
17 UIKit        0x00000001019e2714 -[UIApplication workspaceDidEndTransaction:] + 188 
18 FrontBoardServices     0x000000010444f8c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24 
19 FrontBoardServices     0x000000010444f741 -[FBSSerialQueue _performNext] + 178 
20 FrontBoardServices     0x000000010444faca -[FBSSerialQueue _performNextFromRunLoopSource] + 45 
21 CoreFoundation      0x0000000101556301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
22 CoreFoundation      0x000000010154c22c __CFRunLoopDoSources0 + 556 
23 CoreFoundation      0x000000010154b6e3 __CFRunLoopRun + 867 
24 CoreFoundation      0x000000010154b0f8 CFRunLoopRunSpecific + 488 
25 UIKit        0x00000001019e1f21 -[UIApplication _run] + 402 
26 UIKit        0x00000001019e6f09 UIApplicationMain + 171 
27 05-九宫格      0x0000000100ba195f main + 111 
28 libdyld.dylib      0x0000000103e0a92d start + 1 
29 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

(LLDB)

+1

Stellen Sie sicher, dass keine "Ghost" -Ausgänge mit Ihrem XIB verbunden sind. Sie können alle Steckdosen entfernen und sie einzeln nacheinander hinzufügen, um sicherzustellen, dass Sie keine Steckdose haben, die auf nicht vorhandene UI-Elemente verweist. – Raz

Antwort

0

Überprüfen Sie, ob ihr irgendwelche vorherigen Stellen, die gelöscht wurden aus innerhalb des Storyboards, indem Sie entweder den View-Controller-Inspektor überprüfen und auf Outlets für beliebige Outlets verweisen, die den von Ihnen vorgenommenen Outputs widersprechen, sowie auf das UIVi ew/UILabel.

Verwandte Themen