49

我在 iOS 5 中收到此错误

-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance 0xa217200

但是,我在 iOS 6 中没有收到任何错误。我该如何解决这个问题?这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MyCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; /// SIGABRT error

    if (!cell)
    {
        cell = [[UITableViewCell alloc]
        initWithStyle: UITableViewCellStyleSubtitle
        reuseIdentifier: CellIdentifier];
    }

    return cell;
}
4

2 回答 2

128

编辑:此方法是在 iOS6+ SDK 中新增的。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

UITableViewCell但是在 iOS 5 中,我们通常使用这种方法来创建实例:-

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

在 iOS 5 中,不需要您在 iOS 6 中使用的额外参数。(forIndexPath:)。

所以改变你的方法。它会起作用的。

于 2012-08-18T06:26:19.367 回答
7

这就是您收到错误的原因。根据 iOS 6.0 文档设置 UITableView 类参考状态 dequeueReusableCellWithIdentifier:在 iOS 2.0 及更高版本dequeueReusableCellWithIdentifier:forIndexPath:中可用,在 iOS 6.0 及更高版本中可用。

于 2012-11-22T17:01:39.797 回答