iOS tatableViewCell添加button并获取点击事件
2017-03-14 12:07
711 查看
UIButton *btn = [UIButton
buttonWithType:UIButtonTypeCustom];
btn.frame =
CGRectMake(cell.frame.size.width-70,20,
50.0f, cell.frame.size.height-60);
[btn setTitle:@"预约"
forState:UIControlStateNormal];
btn.backgroundColor =[UIColor
redColor];
[btn addTarget:self
action:@selector(cellBtnClicked:event:)
forControlEvents:UIControlEventTouchUpInside];
//[btn3 addTarget:self action:@selector(onClick3:) forControlEvents:UIControlEventTouchUpInside];
//btn3.tag=indexPath.row;
[cell.contentView
addSubview:btn];
- (void)cellBtnClicked:(id)sender event:(id)event
{
NSSet *touches =[event
allTouches];
UITouch *touch =[touches
anyObject];
CGPoint currentTouchPosition = [touch
locationInView:_tableView];
NSIndexPath *indexPath= [_tableView
indexPathForRowAtPoint:currentTouchPosition];
if (indexPath!=
nil) {
// do something
NSLog(@"%zd",indexPath.row);
}
}
//-(void)onClick3:(UIButton *) sender{
// NSLog(@"%ld",sender.tag);
//}
buttonWithType:UIButtonTypeCustom];
btn.frame =
CGRectMake(cell.frame.size.width-70,20,
50.0f, cell.frame.size.height-60);
[btn setTitle:@"预约"
forState:UIControlStateNormal];
btn.backgroundColor =[UIColor
redColor];
[btn addTarget:self
action:@selector(cellBtnClicked:event:)
forControlEvents:UIControlEventTouchUpInside];
//[btn3 addTarget:self action:@selector(onClick3:) forControlEvents:UIControlEventTouchUpInside];
//btn3.tag=indexPath.row;
[cell.contentView
addSubview:btn];
- (void)cellBtnClicked:(id)sender event:(id)event
{
NSSet *touches =[event
allTouches];
UITouch *touch =[touches
anyObject];
CGPoint currentTouchPosition = [touch
locationInView:_tableView];
NSIndexPath *indexPath= [_tableView
indexPathForRowAtPoint:currentTouchPosition];
if (indexPath!=
nil) {
// do something
NSLog(@"%zd",indexPath.row);
}
}
//-(void)onClick3:(UIButton *) sender{
// NSLog(@"%ld",sender.tag);
//}
相关文章推荐
- iOS 为自定义tableView添加button点击事件后获取其序号
- iOScell中添加button 快速点击Button状态
- iOS中如何通过点击UITableViewCell中的Button来获取当前Cell的indexPath
- 获取不同cell中的button点击事件
- 如何获取不同cell上的button点击事件
- iOS开发封装带有Button的UIView控件,使用target-action模式给button添加点击事件
- IOS 中获取web上button的请求跟点击事件 js
- iOS 23-自定义cell上的button点击事件.
- iOS,OC给button添加block点击事件扩展
- iOS开发封装带有Button的UIView控件,使用block给button添加点击事件
- gridview中button添加事件以及获取点击button那行的索引和数据
- iOS--在UITableViewCell中添加Button,通过Button获取Cell
- iOS开发封装带有Button的UIView控件,使用代理给button添加点击事件
- iOS - 关于 Cell 上 Button 点击效果 Cell添加Button点击无效果处理
- iOS移动中按钮添加点击事件
- 【Cocos2dx】使用CCControlButton创建按钮、按钮点击事件,点击事件中的组件获取,setPosition的坐标问题
- iOS UILabel网址识别添加点击事件及以富文本形式显示
- IOS 6 和 IOS7 UITableViewCell上添加控件的获取
- 根据点击头像的手势获取自定义Cell 的属性, UITableViewCell, 头像, iOS