在table里边的cell上面添加了button cell,如何确定点击的是哪一行

UITableView(11)
直接上代码
@protocol bingdingDelegate &NSObject&
-(void)bingDing:(UIButton *)
typedef void (^ bindingBlock) (NSString *type);
@interface BindingCell : UITableViewCell
@property (strong, nonatomic)
UIButton *BingdingB
@property (nonatomic, weak)id&bingdingDelegate&
[_BingdingBtn addTarget:self action:@selector(goToBingding:) forControlEvents:UIControlEventTouchUpInside];
-(void)goToBingding:(UIButton *)button {
if (_delegate &&[_delegate respondsToSelector:@selector(bingDing:)]) {
[_delegate bingDing:button];
控制器的.m中
-(void)bingDing:(UIButton *)sender {
if ([_tableView indexPathForCell:((BindingCell*)[[sender superview]superview])].row == 0) {
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:27686次
排名:千里之外
原创:100篇
转载:56篇
(1)(4)(1)(7)(5)(3)(4)(9)(8)(9)(6)(3)(7)(7)(9)(13)(16)(20)(20)查看:2895|回复:2
助理工程师
tableview所在的viewcontroller是naviagtioncontroller的rootviewcontroller
现在cell是自定义的,cell里定义了button
现在是想通过点击cell的button来push viewcontroller,不是点tableview的某一行来push
请问这个怎么实现,谢谢。
初级工程师
Button的方法是在自定义的cell里定义的,就是说在自定义的cell里用self.navigationcontroller pushcontroller是不行的吧
助理工程师
那如果不用push的话你还考虑用什么???自定义tableView的cell上添加button按钮,单击button跳转到相应的详情页简单用法 - 简书
<div class="fixed-btn note-fixed-download" data-toggle="popover" data-placement="left" data-html="true" data-trigger="hover" data-content=''>
写了386字,被2人关注,获得了6个喜欢
自定义tableView的cell上添加button按钮,单击button跳转到相应的详情页简单用法
自己在做项目时,项目中的cell上有button按钮,如果说是单击cell跳转到下一页面还比较容易,使用-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath就可以解决,可是在cell上单击button按钮可是没有那么多简单方法.废话不多说直接上代码:-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{//自定义cell代码,这里不做说明//选中Cell不变色的简便用法cell.selectionStyle = UITableViewCellSelectionStyleN.........//*主要代码:在这个里定义一个buttonUIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom];CGRect frame = CGRectMake(230,0,80 ,54 );button.frame =//我是在button上放的图片,不需要的自行更正[button setBackgroundImage:[UIImage imageNamed:@"yanshou"] forState:UIControlStateNormal];[button addTarget:self action:@selector(accessoryButtonTappedAction:) forControlEvents:UIControlEventTouchUpInside];//1,2两种方式都可以经button加在cell上//1将button放到cell上(可以改变button的坐标,长宽)[cell addSubview:button];//2将该button赋给cell属性accessoryView(显示在cell的最后侧居中,只可更改变长宽,不可改变坐标位置)//cell. accessoryView =}//button按钮的点击事件- (void)accessoryButtonTappedAction:(id)sender{//QXOderController是你要跳转到的页面QXOderController *oo = [[QXOderController alloc]init];UIButton *button = (UIButton *)//QXInspectCell是自定义的CellQXInspectCell *cell = (QXInspectCell *)[button superview];NSIndexPath *indexPath = [_tableView indexPathForCell:cell];NSLog(@"indexPath is = %li",(long)indexPath.row);//QXInspectModel是数据modelQXInspectModel *model = _dataSource[indexPath.row];//change是传给你跳转到的QXOderController页面在.h中定义的//zid是model数据里定义的oo.chuanzhi = model.//页面传值[self.navigationController pushViewController:oo animated:YES];}
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
被以下专题收入,发现更多相似内容:
如果你是程序员,或者有一颗喜欢写程序的心,喜欢分享技术干货、项目经验、程序员日常囧事等等,欢迎投稿《程序员》专题。
专题主编:小...
· 246951人关注
分享 iOS 开发的知识,解决大家遇到的问题,讨论iOS开发的前沿,欢迎大家投稿~
· 28862人关注
欢迎各位大神投稿!
· 460人關注
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
选择支付方式:iOS tableViewcell上添加button并定位具体cell上的button - 推酷
iOS tableViewcell上添加button并定位具体cell上的button
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *identifier = @”mycell”;
WorkTypeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[WorkTypeTableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
cell.selectBtn.tag = 100 + indexPath.
[cell.selectBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
//获取对应点击事件的button
-(void)selectBtnClick:(UIbutton *)btn{
UIbutton *button = (UIbutton *)[tableView viewWithTag:btn.tag];
本文永久地址:/15553.html
本文出自IT985博客 ,转载时请注明出处及相应链接。
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致iOS tableViewcell上添加button并定位具体cell上的button
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *identifier = @”mycell”;
WorkTypeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[WorkTypeTableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
cell.selectBtn.tag = 100 + indexPath.
[cell.selectBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
//获取对应点击事件的button
-(void)selectBtnClick:(UIbutton *)btn{
UIbutton *button = (UIbutton *)[tableView viewWithTag:btn.tag];
本文永久地址:/15553.html
本文出自IT985博客 ,转载时请注明出处及相应链接。
最新教程周点击榜
微信扫一扫

我要回帖

更多关于 cell button点击事件 的文章

 

随机推荐