user1072515
user1072515

Reputation: 3

Button action not being called in new view controller

I have a table view as my RootViewController and push another one on a button press with this code.

[[self navigationController] pushViewController:aboutVC animated:YES];

My problem is that my button's actions are not called when they are pressed. I have checked almost everything that I can think of and I am pretty sure that there is a view overtop of my button that is intercepting the user interaction. I have nothing else other than the button and its action coded in my new view controller. I am using a custom cell, but there is nothing in it yet.

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

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.userInteractionEnabled = NO;

    //ADD BUTTONS
    UIButton *redButton = [[UIButton alloc] init];
    redButton.backgroundColor = [UIColor colorWithRed:0.0/255 green:0.0/255 blue:0.0/255 alpha:1.00];
    [redButton addTarget:self action:@selector(redButton:) forControlEvents:UIControlEventTouchUpInside];
    redButton.frame = CGRectMake(9, 44, 40, 39);

    [cell addSubview:redButton];

    [redButton release];
    return cell;
}


- (void)redButton:(id)sender
{
    //Button action will go here
}

any ideas on what i might be doing wrong?

Upvotes: 0

Views: 506

Answers (1)

Narayana Rao Routhu
Narayana Rao Routhu

Reputation: 6323

cell.userInteractionEnabled = NO;
[cell addSubview:redButton];

Replace above lines with below 2 lines of code it will work

cell.userInteractionEnabled = YES;
[cell.contentView addSubview:redButton];

Upvotes: 2

Related Questions