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

标签 iphone objective-c ios ios5 uinavigationcontroller

我按照此 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/

相关文章:

iphone - 点击 X 按钮时从 UISearchBar 中关闭键盘

ios - 处理 NSDateFormatter 语言环境 "feature"的最佳方法是什么?

android - Ionic View App with iOS device which data has not been showed

ios - 将单元格添加到 Collection View 。 swift

ios - 使用 ionic 和 cordova 的 iOS App Transport Security 问题

iphone - 如何检测 UIWebView 上的触摸

iphone - 难以解析包含 '\u00' 等字符的响应

iphone - 构建 ios Promise 时出现 Ionic3 错误,但未出现错误 : 'Error code 65

iphone - 如何在 iOS 上将图像旋转 90 度?

objective-c - 读取 Opera *dat 文件 Objective C