2011-01-31 51 views
0

我有一個標籤欄應用程序。一切正常,我可以切換標籤罰款和一切,除了當我切換到我的第二個標籤ProductViewClass視圖不更新,它吐出了下面的控制檯輸出。除了UIWebView和UILabel之外,我在這個視圖中沒有任何東西。當我刪除UIWebView它運行成功,當我添加另一個它仍然工作。當我將文件所有者的IBOutlet連接到UIWebView時,它只會停止工作。除了合成和釋放productWebViewProductWebView.m唯一的非模板代碼是這樣的:UIWebView拋出NSUnknownKeyException iPad

NSString *urlString = @"http://www.google.com/"; 
    NSURL *theURL = [NSURL URLWithString:urlString]; 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:theURL]; 
    [productWebView loadRequest:urlRequest]; 
    NSLog(@"Google loaded"); 

ProductWebView.h的全文如下:

#import <UIKit/UIKit.h> 
@interface ProductViewClass : UIViewController { 

    IBOutlet UIWebView *productWebView; 
} 

@property(nonatomic, retain) UIWebView *productWebView; 
@end 

這裏是控制檯輸出:

This GDB was configured as "x86_64-apple-darwin".Attaching to process 52523. 
2011-01-30 19:18:28.907 FairCom[52523:40b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4d06eb0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key productWebView.' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00da8be9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00efd5c2 objc_exception_throw + 47 
    2 CoreFoundation      0x00da8b21 -[NSException raise] + 17 
    3 Foundation       0x000296cf _NSSetUsingKeyValueSetter + 135 
    4 Foundation       0x0002963d -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285 
    5 UIKit        0x004a88d6 -[UIRuntimeOutletConnection connect] + 112 
    6 CoreFoundation      0x00d1f2cf -[NSArray makeObjectsPerformSelector:] + 239 
    7 UIKit        0x004a72ed -[UINib instantiateWithOwner:options:] + 1041 
    8 UIKit        0x004a9081 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168 
    9 UIKit        0x00361a94 -[UIViewController _loadViewFromNibNamed:bundle:] + 70 
    10 UIKit        0x0035f709 -[UIViewController loadView] + 120 
    11 UIKit        0x0035f5e3 -[UIViewController view] + 56 
    12 UIKit        0x00372230 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120 
    13 UIKit        0x00370d86 -[UITabBarController transitionFromViewController:toViewController:] + 64 
    14 UIKit        0x00372b7e -[UITabBarController _setSelectedViewController:] + 263 
    15 UIKit        0x003729ed -[UITabBarController _tabBarItemClicked:] + 352 
    16 UIKit        0x002b1a6e -[UIApplication sendAction:to:from:forEvent:] + 119 
    17 UIKit        0x004af1f2 -[UITabBar _sendAction:withEvent:] + 422 
    18 UIKit        0x002b1a6e -[UIApplication sendAction:to:from:forEvent:] + 119 
    19 UIKit        0x003401b5 -[UIControl sendAction:to:forEvent:] + 67 
    20 UIKit        0x00342647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    21 UIKit        0x0034016c -[UIControl sendActionsForControlEvents:] + 49 
    22 UIKit        0x002b1a6e -[UIApplication sendAction:to:from:forEvent:] + 119 
    23 UIKit        0x003401b5 -[UIControl sendAction:to:forEvent:] + 67 
    24 UIKit        0x00342647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    25 UIKit        0x003411f4 -[UIControl touchesEnded:withEvent:] + 458 
    26 UIKit        0x002d60d1 -[UIWindow _sendTouchesForEvent:] + 567 
    27 UIKit        0x002b737a -[UIApplication sendEvent:] + 447 
    28 UIKit        0x002bc732 _UIApplicationHandleEvent + 7576 
    29 GraphicsServices     0x016dea36 PurpleEventCallback + 1550 
    30 CoreFoundation      0x00d8a064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    31 CoreFoundation      0x00cea6f7 __CFRunLoopDoSource1 + 215 
    32 CoreFoundation      0x00ce7983 __CFRunLoopRun + 979 
    33 CoreFoundation      0x00ce7240 CFRunLoopRunSpecific + 208 
    34 CoreFoundation      0x00ce7161 CFRunLoopRunInMode + 97 
    35 GraphicsServices     0x016dd268 GSEventRunModal + 217 
    36 GraphicsServices     0x016dd32d GSEventRun + 115 
    37 UIKit        0x002c042e UIApplicationMain + 1160 
    38 FairCom        0x00001be0 main + 102 
    39 FairCom        0x00001b71 start + 53 
    40 ???         0x00000001 0x0 + 1 
) 
terminate called after throwing an instance of 'NSException' 
sharedlibrary apply-load-rules all 
(gdb) 

感謝您的幫助!

+0

可能重複的[此類不是密鑰的關鍵值編碼兼容](http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for -the-key) – jtbandes 2015-08-01 21:59:38

回答

6

您正在加載一個筆尖。在那個筆尖上,你有一個名爲productWebView的插座,可能是網絡視圖。你看到的例外是告訴你,productWebView插座實際上並不存在。這是它變得奇怪的地方。錯誤說對象<UIViewController 0x4d06eb0>是有這個缺少的出口的那個。奇怪的位是UIViewController而不是實際視圖控制器子類的名稱。這聽起來像你有一個筆尖,其中文件的所有者被設置爲您的視圖控制器子類之一,但在運行時,您實際上只是直接使用UIViewController的實例。您應該驗證代表選項卡欄控制器中代表選項卡的所有視圖控制器都是UIViewController的實際正確子類,而不僅僅是UIViewController本身的實例。

+0

謝謝!我回去看看我的UITabBarItems,他們沒有設置任何特定的筆尖/類,所以這是一個奇蹟,他們爲什麼工作! – SeniorShizzle 2011-02-20 07:43:35