我正在尝试在我的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;
}
答案 0 :(得分:0)
从代码中,DinoTable
是UIView
,没有UITableView
。我猜测你是根据错误将datasource
和delegate
指向DinoTable
。这些应该指向UITableView
。
在UITableView
内添加DinoTable
,并添加您的类可以设置委托/数据源的方法。