Iphone 自定义UITableViewCell按钮操作未调用?
我有一个自定义单元格,里面有一个按钮。我的问题是,单击单元格按钮时,操作方法没有调用 现在我正在做Iphone 自定义UITableViewCell按钮操作未调用?,iphone,Iphone,我有一个自定义单元格,里面有一个按钮。我的问题是,单击单元格按钮时,操作方法没有调用 现在我正在做 UITableViewCell *cell = [self.tblHomeView dequeueReusableCellWithIdentifier:MyIdentifier]; MyCell * mycell2 = ((MyCell*)cell); if (cell == nil) { cell = [[[MyCell alloc] initWithStyle
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];
}
有什么建议吗?Thank's似乎您应该将消息
addTarget:action:forControlEvent:
发送到UIButton的实例,但您正在将其发送到其他对象。是否有column1
和column2
按钮?如果您的MyCell
是从nib文件加载的,请确保IBOutlets设置正确。并确保正确加载xib文件!查看一下,但您并没有将目标操作方法添加到按钮中,而是将其添加到列本身中。您说的是mycell2.column1 addTarget。。。。。这意味着,如果您触摸的是列,而不是按钮,则会调用该方法。@interface MyCell:UITableViewCell{UIButton*column1;UIButton*column2;您是否创建了按钮的属性和合成?是的,我创建了属性和合成column1和column2是按钮?我回答的第二部分如何?您是否尝试用自定义表视图单元格加载按钮xib?