我正在尝试删除或隐藏tableview内部的静态单元格.我试图隐藏它的功能viewDidLoad.这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView beginUpdates];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:YES];
[self.tableView endUpdates];
[self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
部分仍然出现.我正在使用故事板.能帮帮我吗?谢谢!
我使用xcode 4.2和storyboard创建了一个iOS选项卡式应用程序.我在其上添加了一个带有自定义单元格的tableviewcontroller,当单击该行时,我想打开一个tableviewcontroller,我使用下面的代码如下
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
categoryClass *cc = [datas objectAtIndex:indexPath.row];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
iSubProducts *subProducts = [[iSubProducts alloc] init];
subProducts.title = cc.categoryName;
subProducts.catID = cc.categoryID;
[[self navigationController] pushViewController:subProducts animated:YES];
[subProducts release];
}
Run Code Online (Sandbox Code Playgroud)
但是当我点击该行时它会给我以下错误:
*由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'UITableView dataSource必须从tableView返回一个单元格:cellForRowAtIndexPath
在我的iSubProducts tableviewcontroller上,我有以下内容:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"myCell2";
iSubProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
productSubClass *cc = [datas2 objectAtIndex:indexPath.row];
NSLog(@"Product Name: %@", cc.productName);
cell.txtProductName.text = cc.productName;
cell.txtProductDesc.text = cc.productDesc;
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我假设这是错误发生的地方,单元格返回一个nil值.当我尝试使用或从按钮附加iSubProducts tableviewcontroller时,它一切正常,但如果它来自行的单击,则会出现此错误.
我对iOS开发很新,也许从tableviewcontroller打开tableviewcontroller时出现错误,上面有一个自定义单元格.我已经连续两天呆了脑子并且用Google搜索了很多,不幸的是我找不到任何解决方案.我很确定iSubProducts tableviewcontroller上没有错误,因为如果我尝试从按钮推送它,它的工作原理.我需要关于这个问题的建议,我现在对这个问题非常感兴趣.谢谢大家.