objective-c - Objective C > UITableViewCell 按钮不按下

标签 objective-c uitableview uibutton

我在此 tableView 的 cellForRowAtIndexPath 部分中创建了以下按钮:

UIButton *sched_button_a1 = [UIButton buttonWithType:UIButtonTypeCustom];
sched_button_a1.frame = CGRectMake(0, 0, 110, 52);
CGRect frame_a1 = sched_button_a1.frame;

// Resize height based on length of appointment
frame_a1.size.height = heightCalc;
sched_button_a1.frame = frame_a1;

[sched_button_a1 addTarget:self action:@selector(showAppointment:) forControlEvents:UIControlEventTouchUpInside];
[sched_button_a1 setTitle:[NSString stringWithFormat:@"APPT: %@", APPT_ID ] forState:UIControlStateNormal];
sched_button_a1.layer.backgroundColor = [UIColor redColor].CGColor;
[sched_a1 addSubview:sched_button_a1];

如您所见,它正在调用 showAppointment,目前只是:

-(void)showAppointment:(UIButton*)sender {

    NSLog(@"Button pushed");

}

showAppointment 也在这里定义:

-(void)showAppointment:(UIButton*)sender;

该按钮显示良好,并获得正确的文本和背景,并且似乎位于前台,但是,当我单击它时,没有任何反应,并且按钮看起来甚至没有被按下。

我做错了什么或遗漏了什么?

编辑:我已经返回并删除了 sched_a1 View ,以便直接在 contentView 中创建按钮,但这没有效果。看起来唯一被识别的手势仍然是用于滚动表格的手势。点击该按钮似乎不会更改文本的颜色,也不会以其他方式指示该按钮已被按下并且不会创建任何日志条目。

编辑2:添加cellForRowAtIndexPath到粘贴箱 http://pastebin.com/WXezfW96

最佳答案

我最近遇到了类似的问题,我很难理解。我想出的解决方案是设置按钮的边界,并检查 UIControlEventTouchDown 而不是 UIControlEventTouchUpInside。

关于objective-c - Objective C > UITableViewCell 按钮不按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25897326/

相关文章:

ios - TableView 的观察值

swift - 从不同的 ViewController 更改 UIButton

ios - 我可以在没有配置文件的情况下使用 jenkins 构建 iOS 项目吗?

ios - 如何在不使用包的情况下在 react-native 应用程序中显示启动/启动屏幕? (特别是 iOS)

arrays - 访问该数组的正确语法

ios - 无法通过下拉刷新 tableview Controller 中的刷新我的 JSON 数据

ios - 防止用户每秒按下按钮 x 次

ios - 呈现 SKScene 后取消隐藏 UIButtons 时延迟?

ios - YTPlayer将重定向到OAuth2 URL并显示“请稍候”

iphone - 隐藏 map 注释而不删除它们