我有一个内部按钮的自定义单元格。我的问题是对细胞点击链接自定义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];
}
任何提示吗?谢谢
MyCell的邮政编码 – samfisher 2011-12-21 08:47:00
但是您不是将目标操作方法添加到按钮,而是将其添加到列本身。您说mycell2.column1 addTarget .....哪意味着如果您触摸了列而不是按钮,该方法会被调用。 – 2011-12-21 08:49:35
@interface MyCell:UITableViewCell { UIButton * column1; UIButton * column2; – Shafqat 2011-12-21 08:56:03