我已经按照这个Custom 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方法,但是我如何修复它呢?
发布于 2012-07-30 20:12:46
您得到的错误与您的nib有关,而与您的UITableView无关。您应该在nib中检查Customer Detail类的视图是否连接到它的所有者。这就是为什么只要你尝试使用它就会崩溃
[self.navigationController pushViewController:self.customerDetail animated:YES];发布于 2012-07-30 18:09:53
你设置代理了吗?tableView.delegate = self;我想你应该没问题。
发布于 2012-07-30 18:11:49
表视图的子类化不应该导致这样的问题--根据定义,子类做的每件事都比它的父类多做一些事情。您似乎只设置了数据源,而没有设置委托:
tableView.delegate = self;https://stackoverflow.com/questions/11719248
复制相似问题