Ios iPhone-带>;的静态UITableView;1节使用界面生成器
我在应用程序中添加了一个新的TableView。我将单元格类型更改为静态,并将一些标签拖到单元格中。现在我想以编程方式访问单元格。例如:第3节中的第4单元应该在google.com上打开safari 我创建了一个新的UITableViewController类。然后,我将节数更改为3,并向NumberOfCellsSection方法添加了一个switch/case语句 如果我运行应用程序并打开表视图,应用程序将崩溃。有人能帮我设置TableView吗 谢谢 编辑 这是日志Ios iPhone-带>;的静态UITableView;1节使用界面生成器,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,我在应用程序中添加了一个新的TableView。我将单元格类型更改为静态,并将一些标签拖到单元格中。现在我想以编程方式访问单元格。例如:第3节中的第4单元应该在google.com上打开safari 我创建了一个新的UITableViewController类。然后,我将节数更改为3,并向NumberOfCellsSection方法添加了一个switch/case语句 如果我运行应用程序并打开表视图,应用程序将崩溃。有人能帮我设置TableView吗 谢谢 编辑 这是日志 Terminating
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
我找到了一个有效的解决办法 我对CellForRowatineXpath方法进行了如下编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
return cell;
}
现在,我可以使用if语句访问静态单元格,例如:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 2){
if (indexPath.row == 1){
NSLog(@"Tap");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];
}
}
}
请发布崩溃日志。@XCodeMonkey编辑了它。要分别访问不同的单元格,可能需要使用不同的标识符。请在单元格中尝试if或switch语句,以便行访问不同的单元格。查看此链接以更好地了解它是如何完成的…我没有任何标识符,因为我使用的是静态单元格。我是否必须更改cellForRowAtIndexPath方法中的某些内容?在使用静态单元格时,不应该实现任何数据源方法。您应该阅读“iOS表视图编程指南”中的“用数据填充静态表视图”部分。