Question

I created a UITableViewCell in Interface Builder which I have added a UIImageView and a UIButton to. I have given the UIButton an outlet, and hooked it up to a IBAction with the touch up inside event set. I assumed it would call this method, as everything looked like it is hooked up:

- (IBAction)pressedCheckbox:(id)sender {
    [sender setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    NSLog(@"clicked check");

}

Checking the connections tab, I have everything set correctly, the outlet and the action. And I get no errors, but when previewing the app, clicking on that button inside the UITableViewCell does nothing, and I don't see anything in the logs.

Ideas on why it won't let me click my button which is in a UITableViewCell?

EDIT:

Code for cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
                cell = topCell;
                break;
            case 1: 
                cell = cell1;
                break;
        }//end switch

    }//end if

    return cell;
}
Was it helpful?

Solution

I also figured out what the problem was. I was needing to set different heights for cells and was using:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

     if (indexPath.section == 0) {

          switch (indexPath.row) {

               case 0:

                    return 26;

                    break;

          }//end switch

     }//end if

     return tableView.rowHeight; <-- I just added this and it fixed the issue

}

Previously I was only returning a value for cell 0, so it was causing issues with all my other cells

OTHER TIPS

Are you doing this in IB? It may be worth trying - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents (in the loadView method of the owning view controller) to see if the problem is the IB link.

You mean that this is a subclass of UITableViewCell right? Are you sure that you are using this instead of the normal UITableViewCell?

Go to your cellForRowAtIndexPath method implementation and look for the line where you instantiate the cell. Make sure it's instantiating it to whatever your subclass is called, and not UITableViewCell. If you're confused, post the code for your codeForRowAtIndexPath method so we can see it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top