gpt4 book ai didi

iphone - 自定义 TableView 并在 iOS 中使用 didSelectRowAtIndexPath

转载 作者:行者123 更新时间:2023-11-29 04:31:13 25 4
gpt4 key购买 nike

我按照此 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方法,但我该如何修复它?

最佳答案

您收到的错误与您的 Nib 有关,而不是您的 UITableView。您应该检查“客户详细信息”类的 View 是否已连接到 Nib 中的所有者。这就是为什么当你尝试使用它时它就会崩溃

[self.navigationController pushViewController:self.customerDetail animated:YES];

关于iphone - 自定义 TableView 并在 iOS 中使用 didSelectRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11719248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com