2011-12-21 32 views
0

我有一个内部按钮的自定义单元格。我的问题是对细胞点击链接自定义UITableViewCell按钮操作没有调用?

当现在我在做

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];   
    } 

在我的cellForRowAtIndexPath方法,我的方法是操作方法并没有叫:

- (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]; 
} 

任何提示吗?谢谢

+0

MyCell的邮政编码 – samfisher 2011-12-21 08:47:00

+0

但是您不是将目标操作方法添加到按钮,而是将其添加到列本身。您说mycell2.column1 addTarget .....哪意味着如果您触摸了列而不是按钮,该方法会被调用。 – 2011-12-21 08:49:35

+0

@interface MyCell:UITableViewCell { UIButton * column1; UIButton * column2; – Shafqat 2011-12-21 08:56:03

回答

0

好像你应该发送消息addTarget:action:forControlEvent:到UIButton的实例,但是你发送它到不同的东西。是column1column2按钮?如果从nib文件加载MyCell,请确保IBOutlets正确设置。并确保你正确加载xib文件!看看example of loading custom cells from xib

+0

column1和column2是按钮 – Shafqat 2011-12-21 09:01:03

+0

我的答案的第二部分呢?你是否试图用自定义表格视图单元格加载按钮xib? – asdf 2011-12-21 14:03:30

相关问题