UITableView of iOS SDK 6.1 don't compatible with iOS SDK 5.1

旧巷老猫 提交于 2019-12-11 09:22:32

问题


I have created UITableView project in XCode 4.6 with iOS 6.1 SDK, and set target sdk to 5.1, when the app calling dequeueReusableCellWithIdentifier in cellForRowAtIndexPath function, the app throw a exception, the simulator is 5.1, on simulator 6.x is ok.

1: [UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance

2:Terminating app due to uncaught exception NSInvalidArgumentException, reason: -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance


回答1:


If you look at the Apple documentation, you'll see that dequeueReusableCellWithIdentifier: forIndexPath: came in with iOS 6.0.

That means if you try to call this method on iOS 5.X devices, it's going to throw an exception.

It would be better if you used the older "dequeueReusableCellWithIdentifier:" call if possible.

One big difference between the two calls is that the latter (older) one can return nil, in which case you need to alloc/init a new reuseable cell.




回答2:


1. dequeueReusableHeaderFooterViewWithIdentifier
Availability
Available in iOS 2.0 and later.
-> Minimum iOS version required to run this function is iOS 2.0

2 .dequeueReusableCellWithIdentifier:forIndexPath:
Availability
Available in iOS 6.0 and later.
-> Minimum iOS version required to run this function is iOS 6.0

EDIT IF your want to use this function the you can check your current device version and then implement this

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
}


来源:https://stackoverflow.com/questions/14727380/uitableview-of-ios-sdk-6-1-dont-compatible-with-ios-sdk-5-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!