use*_*123 49 uitableview ios ios5 ios6
我在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;
}
Run Code Online (Sandbox Code Playgroud)
Nay*_*yan 129
编辑:此方法是在iOS6 + SDK中新添加的.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
但是在iOS 5中,要创建UITableViewCell我们一般使用此方法的实例: -
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Run Code Online (Sandbox Code Playgroud)
在iOS 5中,不需要在iOS 6中使用的额外参数.(forIndexPath :).
所以改变你的方法.它会工作.
这就是你收到错误的原因.根据iOS 6.0文档集dequeueReusableCellWithIdentifier:,iOS 2.0及更高版本dequeueReusableCellWithIdentifier:forIndexPath:中提供了UITableView类参考, 并且可在iOS 6.0及更高版本中使用.
| 归档时间: |
|
| 查看次数: |
16957 次 |
| 最近记录: |