我已经按照这个自定义UITableViewCell 创建了一个自定义TableView
我创建了一个CustomerCell,然后在ViewController:中这样使用它
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *uniqueIdentifier = @"cutomerCell";
CustomerCell *cell = nil;
cell = (CustomerCell *) [self.tableview dequeueReusableCellWithIdentifier:uniqueIdentifier];
Customer *customer = [self.customers objectAtIndex:[indexPath row]];
if(!cell)
{
NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:nil options:nil];
for(id currentObject in topLevelObject)
{
if([currentObject isKindOfClass:[CustomerCell class]])
{
cell = (CustomerCell *) currentObject;
break;
}
}
}
cell.nameLabel.text = customer.name;
return cell;
}
一切都很好。但随后我启动下一个链接UINavigationController
问题是当我使用这种方法时:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@ "hi");
}
当我单击TableView中的项目时,不会发生任何事情。这可能是因为我实现了Custom TableView
,然后我不能使用didSelectRowAtIndexPath
方法,但我该如何修复它?
您收到的错误与您的笔尖有关,而与UITableView无关。您应该检查Customer Detail类的视图是否连接到其在nib中的所有者。这就是为什么当你尝试使用时它就会崩溃
[self.navigationController pushViewController:self.customerDetail animated:YES];
您设置了委托吗?tableView.delegate=self;我想你应该没事的。
对表视图进行子类化不应该引起这样的问题——根据定义,子类做的每件事都比它的超类多。似乎您只设置了数据源,但设置了委托:
tableView.delegate = self;