UIButton没有在自定义UITableViewCell中获取触摸事件

时间:2010-12-24 19:31:26

标签: iphone ipad ios4

我在IB中设计了一个自定义UItableView Cell。该单元格具有UIButton,并具有相关的操作。此按钮没有获得触摸事件,但是单元本身在调用时会获取事件。

我在这里做错了什么。

+--------------------------------+
|                     +----------+
|  Cell               | Button   |
|                     +----------+
+--------------------------------+

当我点击Button tableviewcell获取事件时。可能有什么不对?

编辑:

我刚检查过,UIButton也在接触触摸事件,但UITableViewCell也是如此。然后在结束时,与UIButton相关的动作不会被调用。

4 个答案:

答案 0 :(得分:2)

我有同样的问题。最后注意到有问题的按钮在属性检查器中未选中“已启用用户交互”复选框。

答案 1 :(得分:0)

这可能不正确,但可以解决,

如果我在代码中动态创建按钮,则应用程序可以正常工作。

答案 2 :(得分:0)

customtablecell.h中 你需要声明一个新的控制器,例如UIViewController *parentViewController;
做财产和合成
写下customtablecell.m文件

中的代码行
-(IBAction)myButtonAction:(id)sender {
 if (self.parentViewController) { 
        [self.parentViewController performSelector:@selector(myButtonClicked: forCellWithLabel:) withObject:sender withObject:[self.NameOfTrack text]];
    }
}

在customtablecell xib中将此-(IBAction)myButtonAction:(id)sender连接到按钮

tableViewController中的

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method
cell.parentViewController = self;





- (void)myButtonClicked:(id)sender forCellWithLabel:(NSString *)text {
    UIButton *button = (UIButton  *)sender;
  //Do some thing

}

答案 3 :(得分:0)

确保您已将状态为UIControlEventTouchUpInside的此按钮与IBAction相关联,并启用了用户交互。然后文件所有者应该接收触摸事件。