[英][UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
[英]tableview not working - [UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
我正在嘗試使用xib
初始化uitableview
但是當我在模擬器中運行應用程序時,拋出以下異常。
2013-06-16 10:40:48.552 CoreDataExample[60661:c07] -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x81765a0
2013-06-16 10:40:48.554 CoreDataExample[60661:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x81765a0'
在我嘗試啟動tableview之后的步驟下面:
viewController
添加UITableViewDelegate
和UITableViewDataSource
。 tableview
插入我的viewController.xib
的視圖。 datasource
並delegate
(按下控制鍵並從組件到文件的所有者拖動鼠標箭頭,然后選擇選項委托)。 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
和- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
在我的viewController.m
。 下面是兩種方法的實現:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
static NSString *identifier = @"identifier";
cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
cell.textLabel.text = @"Olá";
cell.detailTextLabel.text = @"Subtitle" ;
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
return cell;
}
ViewController.h如下:
@interface CDEMainViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
@end
在XIB中,單擊文件所有者,檢查類類型。 我想這是UIViewController。 如果是UIViewController
則將其更改為CDEMainViewController
。 它會正常工作。
你有設定方法嗎?:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
嘗試打開xib文件並重新連接tableView的IBOutlet。 希望對你有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.