NSInvalidArgumentException accessing NSMutableArray in a UITableView

Posted by kashar28 on Stack Overflow See other posts from Stack Overflow or by kashar28
Published on 2010-03-16T22:18:54Z Indexed on 2010/03/16 22:21 UTC
Read the original article Hit count: 107

Filed under:

Hello,

I am a noob in iPhone programming so kindly guide me. I have 5 buttons in a custom UITableViewCell. Following is the code to determine which button was pressed.

In ProductTableCustomCell.m

      -(IBAction) getRating:(id) sender {
        ProductTableView *ptv = (ProductTableView *)self.superview;
        if((UIButton *) sender == box1) {

        [ptv.totalComments addObject:@"BOX2"];

        } else if((UIButton *) sender == box2){
            NSLog(@"Box2");
            [ptv.totalComments addObject:@"BOX2"];
            NSLog(@"Am I here?");
        }else if((UIButton *) sender == box3){
            NSLog(@"Box3");
            [ptv.totalComments addObject:@"BOX3"];
        }else if((UIButton *) sender == box4){
            NSLog(@"Box4");
            [ptv.totalComments addObject:@"BOX4"];
        }else if((UIButton *) sender == box5){
            NSLog(@"Box5");
            [ptv.totalComments addObject:@"BOX5"];
        }

     }

Here totalComments is a NSMutableArray in ProductTableView which is a UITableView. If for example I click button2, then I get the following error:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[UITableView totalComments]: unrecognized selector sent to instance 0x4036e00'**

I don't understand the problem. I have double checked the IBOutlets and IBActions as well. Everything seems proper. I think the problem is in the superview.Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about uitableview