Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell not always selectable?

I'm in the middle of trying to debug an issue with a new app, and something isn't right. In the app, I'm setting up custom UITableViewCells by adding 2 UILabels and 1 UIImageView directly to the cell.contentView

In my app, certain table view cells werent selectable ( they werent responding to tap events ). The 2nd cell on the screen was always never selectable, and then random other cells also werent selectable.

In my effort to debug, I stripped everything down the following bare essentials of code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *CellIdentifier = @"ReviewCell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  }
  cell.textLabel.text = @"foo";
  return cell;
}

Even this is generic, boiler plate code, that looks like the following:

not all the cells are selectable.

What am I missing?

update

as an updated here is my row selection code if interested

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ReviewWebViewController *rvc = [[ReviewWebViewController alloc] initWithReview:[self.reviews objectAtIndex:indexPath.row]];
    [self.navigationController pushViewController:rvc animated:YES];
    [rvc release], rvc=nil;
}
like image 662
cpjolicoeur Avatar asked Jan 13 '11 02:01

cpjolicoeur


1 Answers

A lot of things have been mentioned, which I will not re-iterate.

But make sure that the elements you add to the UITableViewCell have their userInteractionEnabled set to NO. Especially when not using IB, never make too many assumptions about defaults.

like image 145
mvds Avatar answered Sep 17 '22 13:09

mvds