2012-07-30 30 views
0

工作時,我有這樣的標題:IOS - 的tableView:numberOfRowsInSection ... NSInvalidArgumentException與UITableView的

@interface MyBusinessesController : UIViewController 

@property (weak, nonatomic) IBOutlet UITableView *businessList; 

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

@end 

,我有這在我的.m文件:

#import "MyBusinessesController.h" 

@interface MyBusinessesController() 

@end 

@implementation MyBusinessesController 

@synthesize businessList; 
@synthesize loadingLabel; 

- (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. 

     NSLog(@"HIDING 1"); 
    // HIDE THE LIST UNTIL IT LOADS 
    self.businessList.hidden=TRUE; 
     NSLog(@"HIDING 2");  
} 

- (void)viewDidUnload 
{ 
    [self setLoadingLabel:nil]; 
    [self setBusinessList:nil]; 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

當這個控制器運行,兩個NSLOG行都執行,並在此之後發生異常。

這裏是例外:

-[MyBusinessesController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6a8f330 
2012-07-29 21:31:38.355 BusinessPlan[3973:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyBusinessesController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6a8f330' 
*** First throw call stack: 
(0x13d5022 0x1566cd6 0x13d6cbd 0x133bed0 0x133bcb2 0x1fd06b 0x1ff862 0xad66d 0xad167 0xb0134 0xb4623 0x5dd42 0x13d6e42 0x1d8d679 0x1d97579 0x1d1c4f7 0x1d1e3f6 0x1d1dad0 0x13a999e 0x1340640 0x130c4c6 0x130bd84 0x130bc9b 0x12be7d8 0x12be88a 0x1f626 0x1bfd 0x1b65) 

會有人能夠幫助我明白是怎麼回事錯在這裏?

謝謝!

+0

您的表視圖認爲'MyBusinessesController'是它的數據源並正在調用所需的數據源方法。從你發佈的細節來看,設置的方式並不明顯。 – 2012-07-30 01:55:09

回答

1

您可能已將MyBussinessViewController設置爲接口構建器中的數據源,但您未在其中設置數據源方法。您可以通過右鍵單擊界面構建器中的tableview並查看數據源字段連接到的內容來進行檢查。

僅供參考,您需要:

tableView:numberOfRowsInSection: 
numberOfSectionsInTableView: 
tableView:cellForRowAtIndexPath: 

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

編碼愉快。

相關問題