0

I have this code here:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[MMSideDrawerTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    switch (indexPath.section) {
        case MMDrawerSectionOne:
            if(indexPath.row == 0){
                [cell.textLabel setText:@"Menu Item 1"];
            }
            break;

        case MMDrawerSectionTwo:
            if(indexPath.row == 0){
                [cell.textLabel setText:@"Menu Item 2"];
            }
            break;

        case MMDrawerSectionThree:
            if(indexPath.row == 0){
                [cell.textLabel setText:@"Menu Item 3"];
            }else{
                [cell.textLabel setText:@"Menu Item 4"];
            }
            break;
    }

    cell.backgroundColor = [UIColor clearColor];

    cell.textLabel.textColor = [UIColor whiteColor];

    cell.contentView.alpha = 0.7;

    // Code to add background when user taps
    UIView *bgColorView = [[UIView alloc] init];
    bgColorView.backgroundColor = [UIColor colorWithRed:(55.0/255.0) green:(55/255.0) blue:(55/255.0) alpha:0.3];
    bgColorView.layer.masksToBounds = YES;
    cell.selectedBackgroundView = bgColorView;

    NSLog(@"%@", indexPath);

    return cell;
}

and this code here:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Testing");
}

Whenever I tap a row on the UITable didSelectRowAtIndexPath does nothing. Is there anything I am doing wrong?

Peter

Peter Stuart
  • 2,362
  • 7
  • 42
  • 73

1 Answers1

0

Open InterfaceBuilder and select your UITableView. A few questions to ask yourself:

  1. Is "Selection" set to "Single" or "Multiple"? Having it set to "No Selection" will not fire didSelectRowAtIndexPath:
  2. Is "User Interaction Enabled" checked? If not, didSelectRowAtIndexPath: will not fire

You can change these properties programmatically as follows:

self.tableView.allowsMultipleSelection = NO;
self.tableView.allowsSelection = YES;
self.tableView.userInteractionEnabled = YES;

If that doesn't work, try the accepted answer for this SO post here.

Community
  • 1
  • 1
ebandersen
  • 2,362
  • 26
  • 25