2011-07-26 13 views
2

這是一個新的。我測試我的各種viewcontrollers越來越我的標籤欄加載的,所以我把這個其中之一:基本UILabel的奇怪的鍵值編碼錯誤

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
UILabel*yo=[[UILabel alloc] init]; 
self.testlabel=yo; 
self.testlabel.text=[NSString stringWithFormat:@"sup"]; 

[yo release]; 

這是當我點擊標籤按鈕該控制器我得到什麼:

2011-07-26 14:05:37.773撿取器[802:707] 由於未捕獲的異常'NSUnknownKeyException'而終止應用,原因:'[setValue:forUndefinedKey:]:該類不是符合密鑰值的編碼關鍵測試標籤「。 *

什麼在這個世界上?我必須在這裏做一些特別基本和錯誤的事情。任何人都可以發現它?

我在.H和.M得到這個:

@interface SingleVC : UIViewController 

@property (nonatomic, retain) IBOutlet UILabel*testlabel; 

@end 

@implementation SingleVC 

@synthesize testlabel; 

我收到以下錯誤堆棧(我不知道如何讀):

*** Call stack at first throw: 
(
    0 CoreFoundation      0x00dc25a9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00f16313 objc_exception_throw + 44 
    2 CoreFoundation      0x00dc24e1 -[NSException raise] + 17 
    3 Foundation       0x00794677 _NSSetUsingKeyValueSetter + 135 
    4 Foundation       0x007945e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285 
    5 UIKit        0x0021030c -[UIRuntimeOutletConnection connect] + 112 
    6 CoreFoundation      0x00d388cf -[NSArray makeObjectsPerformSelector:] + 239 
    7 UIKit        0x0020ed23 -[UINib instantiateWithOwner:options:] + 1041 
    8 UIKit        0x00210ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168 
    9 UIKit        0x000c6628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70 
    10 UIKit        0x000c4134 -[UIViewController loadView] + 120 
    11 UIKit        0x000c400e -[UIViewController view] + 56 
    12 UIKit        0x000d6f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120 
    13 UIKit        0x000d5aaa -[UITabBarController transitionFromViewController:toViewController:] + 64 
    14 UIKit        0x000d78a2 -[UITabBarController _setSelectedViewController:] + 263 
    15 UIKit        0x000d7711 -[UITabBarController _tabBarItemClicked:] + 352 
    16 UIKit        0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    17 UIKit        0x00216ce6 -[UITabBar _sendAction:withEvent:] + 422 
    18 UIKit        0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    19 UIKit        0x000a4799 -[UIControl sendAction:to:forEvent:] + 67 
    20 UIKit        0x000a6c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    21 UIKit        0x000a4750 -[UIControl sendActionsForControlEvents:] + 49 
    22 UIKit        0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    23 UIKit        0x000a4799 -[UIControl sendAction:to:forEvent:] + 67 
    24 UIKit        0x000a6c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    25 UIKit        0x000a57d8 -[UIControl touchesEnded:withEvent:] + 458 
    26 UIKit        0x00038ded -[UIWindow _sendTouchesForEvent:] + 567 
    27 UIKit        0x00019c37 -[UIApplication sendEvent:] + 447 
    28 UIKit        0x0001ef2e _UIApplicationHandleEvent + 7576 
    29 GraphicsServices     0x00ffb992 PurpleEventCallback + 1550 
    30 CoreFoundation      0x00da3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    31 CoreFoundation      0x00d03cf7 __CFRunLoopDoSource1 + 215 
    32 CoreFoundation      0x00d00f83 __CFRunLoopRun + 979 
    33 CoreFoundation      0x00d00840 CFRunLoopRunSpecific + 208 
    34 CoreFoundation      0x00d00761 CFRunLoopRunInMode + 97 
    35 GraphicsServices     0x00ffa1c4 GSEventRunModal + 217 
    36 GraphicsServices     0x00ffa289 GSEventRun + 115 
    37 UIKit        0x00022c93 UIApplicationMain + 1160 
    38 Pickers        0x000025c9 main + 121 
    39 Pickers        0x00002545 start + 53 
) 
terminate called throwing an exceptionCurrent language: auto; currently objective-c 
kill 
quit 
+0

您是否嘗試過註釋'self.testlabel = yo;'和'self.testlabel.text = [NSString stringWithFormat:@「sup」];'?你能把問題縮小到一個或另一個嗎? –

+0

我注意到,如果我完全斷開與IB的連接並且不更改代碼,則不會出現錯誤。所以我想,在IB中有一些東西。我只是控制 - 從文件所有者拖動到標籤,並選擇testlabel,唯一的選擇,因爲我沒有做過其他編碼。 – johnbakers

+0

這將是很多這個堆棧跟蹤會更容易閱讀,如果你將它格式化爲代碼 –

回答

1

所以在其他網站上的一些谷歌搜索後,事實證明,不少人有過這樣的完全相同的和基本的問題。我發現這裏的解決方案:

https://discussions.apple.com/thread/1598422?threadID=1598422

我檢查我的班每個控制器的個別筆尖內,但你也必須設定選項卡控制器類爲好,爲每個項目(我已經設置每個標籤欄項目的筆尖名稱,但不是類別)。

因此,問題已經解決,並且如預期的那樣相當基本。

雖然這是一個爲什麼創建的錯誤是關鍵值編碼的原因。

+0

問題是'鍵值編碼',因爲文件所有者的類是UIViewController而不是SingleVC,因爲加載的子文件裝載機器調用setValue :forKey:。UIViewController沒有那個鍵,因此錯誤。那正是我試圖帶你回答我的問題和答案的原因。閱讀此文檔以獲取更多信息http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html –

+0

感謝法案。你的問題似乎是針對每個標籤項目的筆尖中的文件所有者,並且沒有針對標籤欄的根控制器筆尖,這是我忽略的。 – johnbakers

0

也許IB中的某個對象以前有一個名爲testlabel的IBOutlet的連接?

停止ObjC例外調試併發布您的堆棧跟蹤,如果不是很明顯

+0

我從頭開始這個應用程序,沒有其他網點或我在IB使用過的對象。這個男人真的很難過我。 – johnbakers

+0

我添加了堆棧跟蹤錯誤 – johnbakers

+0

也許你已經把你的類的文件所有者的類從連接改回UIViewController後? –