在iOS5中我的UITableView dequeueReusableCellWithIdentifier错误

我在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; } 

编辑 :这个方法是在iOS6 + SDK中新增加的。

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

但在iOS 5中,为了创buildUITableViewCell实例,我们通常使用这个方法:

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

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

这就是为什么你会得到这个错误。 根据iOS 6.0文档设置UITableView类参考指出dequeueReusableCellWithIdentifier:在iOS 2.0及更高版本中可用, dequeueReusableCellWithIdentifier:forIndexPath:在iOS 6.0和更高版本中可用。