2011-04-30 23 views
1

我不知道爲什麼我收到此錯誤 我創建了一個常規的標籤欄應用 取得5項(編譯和運行) 再放入標籤之一的tableview,把下面的代碼,我得到這個錯誤的Xcode「NSInvalidArgumentException」的,理由是:「 - [治癒上海華]:無法識別的選擇發送到實例0x4e3b7b0」

cure.h

#import <UIKit/UIKit.h> 

@interface cure : UIViewController 
<UITableViewDataSource, UITableViewDelegate> 
{ 
    NSArray *exercises; 
} 

@end 

cure.m

#import "cure.h" 

@implementation cure 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

    // create a cell 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier:@"cell"]; 
    } 

    // set the main text 
    cell.textLabel.text = [exercises objectAtIndex:indexPath.row]; 

    // return the cell. 
    return cell; 
} 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    exercises = [[NSArray alloc] 
       initWithObjects:@"An Interesting Title", 
       @"A Not That Interesting Title", 
       @"And Still Another Title", nil]; 

    [super viewDidLoad]; 
} 



- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end 

在mainwindows.xib 我有正確的選項卡類名 「治癒」

錯誤

2011-04-29 22:22:06.446 week 3 week clear [4950:40b] -[cure superview]: unrecognized selector sent to instance 0x4e3b7b0 
2011-04-29 22:22:06.451 peek 3 week clear [4950:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00dc15a9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00f15313 objc_exception_throw + 44 
    2 CoreFoundation      0x00dc30bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00d32966 ___forwarding___ + 966 
    4 CoreFoundation      0x00d32522 _CF_forwarding_prep_0 + 50 
    5 UIKit        0x002e2365 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 77 
    6 UIKit        0x002e0aa3 -[UIView(Hierarchy) addSubview:] + 57 
    7 UIKit        0x002e87c1 -[UIView initWithCoder:] + 840 
    8 Foundation       0x00017c24 _decodeObjectBinary + 3296 
    9 Foundation       0x00016d91 _decodeObject + 224 
    10 UIKit        0x004ac979 -[UIRuntimeConnection initWithCoder:] + 212 
    11 Foundation       0x00017c24 _decodeObjectBinary + 3296 
    12 Foundation       0x000189f5 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1354 
    13 Foundation       0x00019024 -[NSArray(NSArray) initWithCoder:] + 596 
    14 Foundation       0x00017c24 _decodeObjectBinary + 3296 
    15 Foundation       0x00016d91 _decodeObject + 224 
    16 UIKit        0x004abc36 -[UINib instantiateWithOwner:options:] + 804 
    17 UIKit        0x004adab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168 
    18 UIKit        0x00363628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70 
    19 UIKit        0x00361134 -[UIViewController loadView] + 120 
    20 UIKit        0x0036100e -[UIViewController view] + 56 
    21 UIKit        0x00373f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120 
    22 UIKit        0x00372aaa -[UITabBarController transitionFromViewController:toViewController:] + 64 
    23 UIKit        0x003748a2 -[UITabBarController _setSelectedViewController:] + 263 
    24 UIKit        0x00374711 -[UITabBarController _tabBarItemClicked:] + 352 
    25 UIKit        0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    26 UIKit        0x004b3ce6 -[UITabBar _sendAction:withEvent:] + 422 
    27 UIKit        0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    28 UIKit        0x00341799 -[UIControl sendAction:to:forEvent:] + 67 
    29 UIKit        0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    30 UIKit        0x00341750 -[UIControl sendActionsForControlEvents:] + 49 
    31 UIKit        0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    32 UIKit        0x00341799 -[UIControl sendAction:to:forEvent:] + 67 
    33 UIKit        0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    34 UIKit        0x003427d8 -[UIControl touchesEnded:withEvent:] + 458 
    35 UIKit        0x002d5ded -[UIWindow _sendTouchesForEvent:] + 567 
    36 UIKit        0x002b6c37 -[UIApplication sendEvent:] + 447 
    37 UIKit        0x002bbf2e _UIApplicationHandleEvent + 7576 
    38 GraphicsServices     0x01719992 PurpleEventCallback + 1550 
    39 CoreFoundation      0x00da2944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    40 CoreFoundation      0x00d02cf7 __CFRunLoopDoSource1 + 215 
    41 CoreFoundation      0x00cfff83 __CFRunLoopRun + 979 
    42 CoreFoundation      0x00cff840 CFRunLoopRunSpecific + 208 
    43 CoreFoundation      0x00cff761 CFRunLoopRunInMode + 97 
    44 GraphicsServices     0x017181c4 GSEventRunModal + 217 
    45 GraphicsServices     0x01718289 GSEventRun + 115 
    46 UIKit        0x002bfc93 UIApplicationMain + 1160 
    47 peek 3 week clear     0x00002658 main + 102 
    48 peek 3 week clear     0x000025e9 start + 53 
) 
terminate called after throwing an instance of 'NSException' 
Program received signal: 「SIGABRT」. 

我到底做錯了什麼? 謝謝

回答

2

您可能已將「cure」類分配給Interface Builder中「標識」選項卡中的UIView。 「cure」是一個視圖控制器,因此它不會實現任何UIView方法(如-superview),因此在嘗試加載nib時會引發異常。在你的代碼中你有很多泄漏,請閱讀一些關於Objective-C中的內存管理(也許也是關於Cocoa命名約定)。

+0

謝謝你的迴應,我要扔教程,所以對於記憶鏈接,我會了解到幾個類。我正在對其中一個選項卡中的代碼進行微小更改,以在一個選項卡中添加tableview他們的標籤。我不確定我是否理解應該如何設置。如果你想要一個tableview從類cure.h cure.m中加載數據,那麼xib文件名是dacure.xib,那麼這個過程是什麼。謝謝 – borgy2 2011-04-30 15:36:33

相關問題