0

I have a custom cell with a button inside. My problem is action method is not calling when click on cell button

Right now I'm doing

 UITableViewCell *cell = [self.tblHomeView dequeueReusableCellWithIdentifier:MyIdentifier];
    MyCell * mycell2 = ((MyCell*)cell);
    if (cell == nil) {
        cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];

        [mycell2.column1 addTarget:self action:@selector(column1Selected:) forControlEvents:UIControlEventTouchDown];
        [mycell2.column2 addTarget:self action:@selector(column1Selected:) forControlEvents:UIControlEventTouchDown];        
    }

In my cellForRowAtIndexPath method and my method is:

- (void) column1Selected: (id) sender
{
    UIAlertView *alert = [[ UIAlertView alloc]                          
                          initWithTitle: @" Alert"                          
                          message: [NSString stringWithFormat: @"button %d",((UIButton *) sender).tag]
                          delegate: nil                          
                          cancelButtonTitle: @" OK"                          
                          otherButtonTitles: nil];    
    [alert show] ;
    [alert release];
}

Any tips? Thank's

rckoenes
  • 69,092
  • 8
  • 134
  • 166
Shafqat
  • 21
  • 2

1 Answers1

0

Seems that you should send message addTarget:action:forControlEvent: to instance of UIButton, but you are sending it to something different. Are column1 and column2 buttons? If your MyCell is loaded from nib file, make sure IBOutlets correctly set up. And make sure that you load xib files correctly! Take a look at example of loading custom cells from xib

Community
  • 1
  • 1
Nik
  • 9,063
  • 7
  • 66
  • 81