我在表格单元格上有一个UIButton,用于弹出UIActionSheet,但问题是didSelectRowAtIndexPath捕获该触摸并且其操作优先。当用户触摸按钮时,有什么聪明的方法可以覆盖该操作,当用户按下单元格中的其他位置时仍然有默认操作?
太糟糕了,没有MoveToFront属性。
答案 0 :(得分:3)
如何在单元格上添加按钮
我正在放一个样本
in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
...
UIButton *btnDetail = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;
[btnDetail setFrame:CGRectMake(225.0f, 15.0f, 65.0f, 20.0f)] ;
//btnDetail.backgroundColor = [UIColor grayColor];
[btnDetail setTitle:@"Detail" forState:UIControlStateNormal];
[btnDetail setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
[btnDetail.titleLabel setFont:[UIFont fontWithName:@"Verdana-Bold" size:12]];
[btnDetail setBackgroundColor:[UIColor clearColor]];
[btnDetail sizeThatFits:btnDetail.frame.size];
[cell addSubview:btnDetail];
[btnDetail addTarget:self
action:@selector(function1:)
forControlEvents:UIControlEventTouchUpInside];
[btnDetail setImage:[UIImage imageNamed:@"btn-detail.png"] forState:UIControlStateNormal];
如果你写了
[btnDetail addTarget:self
action:@selector(function1:)
forControlEvents:UIControlEventTouchUpInside];
您的按钮应该能够捕获触摸事件,并且应该调用function1 ...触摸事件......