Reputation: 9376
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'
Upvotes: 0
Views: 1836
Reputation: 112
@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.
Upvotes: 1
Reputation: 3586
To my knowledge, the method dequeueReusableCellWithIdentifier:forIndexPath:
was added in iOS 6.0 only.
Better use dequeueReusableCellWithIdentifier:
Upvotes: 7