我想用故事板创建UITableView,如图所示:
和ITViewController.m中的委托方法如下:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ITTableViewCell *cell = (ITTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ITTableViewCell"];
return cell;
}
当我运行我的应用时,我收到错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
似乎没有单元格已初始化,我该如何解决这个问题? THKS!
答案 0 :(得分:-1)
你可以像这样初始化单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ITTableViewCell";
UTTableViewCell *cell = (UTTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}