0

I have an app that has been working great on iOS6.1. Today I realized I should probably try to make this compatible for iOS5 as well. I tried running it on the iOS 5 simulator and am getting an exception thrown on my dequeCell method call. I can't figure out why as it works wonderfully on iOS6. Anyone else come across this problem?

- (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'
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Chase Roberts
  • 9,082
  • 13
  • 73
  • 131

2 Answers2

7

To my knowledge, the method dequeueReusableCellWithIdentifier:forIndexPath: was added in iOS 6.0 only.

Better use dequeueReusableCellWithIdentifier:

J_D
  • 3,526
  • 20
  • 31
  • Perfect. Also, also all of my buttons have stopped working. They display alright but it seems they aren't being tied to the code, anything you can think of off the top of your head? I would like to avoid posting another stupid question if I can. – Chase Roberts Dec 18 '12 at 19:42
  • Do you man buttons inside your cell? By 'they aren't being tied', do you mean that your buttons are IBOutlets and the are not being assigned? How are they created... – J_D Dec 19 '12 at 14:34
1

@Chase, I ran into the same problem set today as well when trying to make my app compatible with iOS 5.1.

A way I got my buttons to work is to utilize a Gesture Recognizer and in the tapDetected delegate method that you implement, query which button you want and call it directly in the code.
Register the Recognizer in your ViewDidLoad

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.delegate = self;
[self.view addGestureRecognizer:tapRecognizer];


    - (void)tapDetected:(UIGestureRecognizer*)tap{
NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ( 6 == [[versionCompatibility objectAtIndex:0] intValue] ) {
    [self.view endEditing:YES];
} else {
    if (CGRectContainsPoint(self.createSessionButton.frame, [tap locationInView:self.view])) {
        [self.view endEditing:YES];
        [self createNewSession:nil];
    }
   }

}

The reason the iOS check is there is because in ios 6 this is not an issue. Sorry for bad formatting, still new to posting here.

  • Can you post the code sample in addition to these directions (which look good, BTW)? – Lizz Dec 26 '12 at 18:58