【发布时间】:2014-06-04 14:27:04
【问题描述】:
我试图在我的 ViewController 上加载一个自定义 UIView ,这个 UIView 加载一个 xib 文件并有一个 tableView ,所以当我将 dataSource 和 delegate 与其文件的所有者连接时,当我尝试午餐应用程序时,由于此消息而崩溃:
TABLE VIEW LOAD
-[DinoViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to
instance 0x993b070 *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[DinoViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to
instance 0x993b070'
*** First throw call stack:
这是我的代码:
//DinoViewController
- (IBAction)searchDino:(id)sender {
DinoTable* tableview = [[DinoTable alloc]initWithFrame:CGRectMake(0,0,384,1024)];
NSArray * dinoTableView = [[NSBundle mainBundle] loadNibNamed:@"DinoTable" owner:self options:nil];
tableview = dinoTableView[0];
[self.view addSubview:tableview];
}
.TableView:
// DinoTable.h
@interface DinoTable : UIView <UITableViewDataSource , UITableViewDelegate> {
NSArray *list;
}
// DinoTable.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"dinoName" ofType:@"plist"] ;
list = [NSArray arrayWithContentsOfFile:filePath];
NSLog(@"TABLE VIEW LOAD");
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [list objectAtIndex:indexPath.row];
return cell;
}
【问题讨论】:
-
这可能会对您有所帮助...stackoverflow.com/a/23403979/294884
标签: ios objective-c uitableview