【问题标题】:UITableView of iOS SDK 6.1 don't compatible with iOS SDK 5.1iOS SDK 6.1 的 UITableView 与 iOS SDK 5.1 不兼容
【发布时间】:2013-02-06 10:59:21
【问题描述】:

我在 XCode 4.6 中使用 iOS 6.1 SDK 创建了UITableView 项目,并将目标 sdk 设置为 5.1,当应用程序在 cellForRowAtIndexPath 函数中调用 dequeueReusableCellWithIdentifier 时,应用程序抛出异常,模拟器是 5.1,在模拟器6.x就可以了。

1: [UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: 无法识别的选择器发送到实例

2:由于未捕获的异常NSInvalidArgumentException,正在终止应用程序,原因:-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: 无法识别的选择器发送到实例

【问题讨论】:

  • 粘贴更多cellForRowAtIndexPath的代码..
  • dequeueReusableCellWithIdentifier:forIndexPath 这个函数是在 ios6.0 中添加的,所以你不能在 ios5 中用这个代码运行应用程序
  • 这是我的错。如果需要,我应该在 5.x 中使用不带 forIndexPath 的 dequeueReusableCellWithIdentifier,并在 6.x 及更高版本中使用 dequeueReusableCellWithIdentifier:forIndexPath:。

标签: iphone uitableview ios5.1 ios6.1


【解决方案1】:

1. dequeueReusableHeaderFooterViewWithIdentifier
可用性
适用于 iOS 2.0 及更高版本。
-> 运行此功能所需的最低 iOS 版本为 iOS 2.0

2 .dequeueReusableCellWithIdentifier:forIndexPath:
可用性
适用于 iOS 6.0 及更高版本。
-> 运行此功能所需的最低 iOS 版本为 iOS 6.0

编辑 如果你想使用这个功能,你可以检查你当前的设备版本,然后实现这个

NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
NSLog(@"curr version = %f",[currSysVer floatValue]);

if ([currSysVer floatValue] >= 6) {
    //iOS 6.0 and later code
    // dequeueReusableCellWithIdentifier:forIndexPath:
}
else{
    //dequeueReusableHeaderFooterViewWithIdentifier
}

【讨论】:

  • 谢谢,我应该使用不带forIndexPath参数的dequeueReusableCellWithIdentifier。
【解决方案2】:

如果您查看 Apple 文档,您会发现 dequeueReusableCellWithIdentifier: forIndexPath: 是随 iOS 6.0 一起提供的。

这意味着如果您尝试在 iOS 5.X 设备上调用此方法,它将引发异常。

如果可能的话,最好使用旧的"dequeueReusableCellWithIdentifier:" 调用。

这两个调用之间的一个很大区别是后者(旧的)一个可以返回 nil,在这种情况下,您需要分配/初始化一个新的可重用单元。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 2012-12-15
    • 2015-01-18
    相关资源
    最近更新 更多