[英]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的實例,但是您將其發送給其他對象。 是column1
和column2
按鈕嗎? 如果您的MyCell
是從nib文件加載的,請確保正確設置了IBOutlets。 並確保正確加載xib文件! 看一下從xib加載定制單元的示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.