iOS 5.1 dequeueReusableCellWithIdentifier抛出NSInvalidArgument异常

Cha*_*rts 0 objective-c uitableview ios5.1

我有一个在iOS6.1上运行良好的应用程序.今天我意识到我应该尝试使这兼容iOS5.我尝试在iOS 5模拟器上运行它,并在我的dequeCell方法调用上抛出一个异常.我无法弄清楚为什么它在iOS6上运行得非常好.还有其他人遇到过这个问题吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = //throws exception here
     [tableView dequeueReusableCellWithIdentifier:CellIdentifier 
                                     forIndexPath:indexPath];
    cell.accessoryView = nil;
    cell.backgroundColor = [UIColor colorWithRed:.97 
                                           green:.97 
                                            blue:.97 
                                           alpha:1];
    cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    ...
    return cell;
}

-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized 
 selector sent to instance 0x8a3a000 -*** Terminating app due to uncaught 
 exception 'NSInvalidArgumentException', reason: '-[UITableView 
 dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector 
 sent to instance 0x8a3a000'
Run Code Online (Sandbox Code Playgroud)

J_D*_*J_D 7

据我所知,该方法dequeueReusableCellWithIdentifier:forIndexPath:仅在iOS 6.0中添加.

更好用 dequeueReusableCellWithIdentifier: