繁体   English   中英

自定义UITableViewCell按钮操作未调用?

[英]Custom UITableViewCell button action not calling?

我有一个带有按钮的自定义单元格。 我的问题是单击单元格按钮时动作方法未调用

现在我在做

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

有小费吗? 谢谢

似乎您应该将消息addTarget:action:forControlEvent:发送到UIButton的实例,但是您将其发送给其他对象。 column1column2按钮吗? 如果您的MyCell是从nib文件加载的,请确保正确设置了IBOutlets。 并确保正确加载xib文件! 看一下从xib加载定制单元的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM