dequeueReusableCellWithIdentifier error in my UITableView in iOS5

限于喜欢 提交于 2019-12-18 10:15:17

问题


I am getting this error in iOS 5

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

However, I get no errors in iOS 6. How can I fix this problem? Here's my code:

- (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;
}

回答1:


EDIT: This method is newly added in iOS6+ SDK.

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

But in iOS 5, to create instance of UITableViewCell we generally use this method :-

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

In iOS 5, there is no need of extra parameter which you have used in iOS 6. (forIndexPath:).

So change your method. It will work.




回答2:


Here's why you're getting the error. As per the iOS 6.0 Documentation Set the UITableView Class Reference states that dequeueReusableCellWithIdentifier: is available in iOS 2.0 and later and dequeueReusableCellWithIdentifier:forIndexPath: is available in iOS 6.0 and later.



来源:https://stackoverflow.com/questions/12016331/dequeuereusablecellwithidentifier-error-in-my-uitableview-in-ios5

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