通过点击cell上的Button获取tableView的indexPath

- (void)buttonClickedWith:(UIButton *)button event:(UIEvent *)event
{
    NSSet *touches =[event allTouches];
    UITouch *touch =[touches anyObject];
    CGPoint point = [touch locationInView:mainTableView];
    NSIndexPath *indexPath= [mainTableView indexPathForRowAtPoint:point];
}
时间: 2024-08-11 05:33:35

通过点击cell上的Button获取tableView的indexPath的相关文章

ios 添加到cell 上的button点击无效!扩大button的点击区域(黑魔法)

一般情况下点击效果都是正常的!要不然你对它做了什么?一般细心的小伙伴都没有遇到这种情况,但是呢! 当然我是二班的!在这里我主要讲两个问题,解决问题和普及魔法. 一.普及问题(button在cell上点击无效) 自定义一个cell,cell里边creat了一个button!然后调试了半天,什么反应都没有! 1.button的enable 设置为yes可点击的. 1.我以为我设置了交互禁用! self.userInteractionEnabled = YES; 2.button的frame越界了!

Ios点击地图上某一点获取该点的经纬度

ios开发中常常会用到地图控件MKMapView,可以用如下方法在点击MKMapView中某点的时候获取改点的经纬度: 假如声明了一个MKMapView为myMapView 1.在地图中添加一个手势,这个手势是一个点击动作,点击时会调用tapPress这个方法 UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPress:)];[myMapV

获取cell上按钮事件

原由:点击cell上的按钮,无法获取button对应的cell位置 //获取按钮上层控件,也就是cell本身 AccountCell *cell= (AccountCell *)[按钮名称 superview]; //获取该cell本身的位置 NSIndexPath *indexPath=[self.collectionView indexPathForCell:cell];

关于UITableView选中效果以及自定义cell上的控件响应事件

tableView默认的点击效果是:点击cell:A,出现点击效果,点另一个cell:B的时候,A的点击效果才会消失. 1.对于tableView,比较常用的效果,是点击表格行,出现效果,点击完毕,效果消失 那么就要在代码里做一些设置.代码如下: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath

iOS-UITableView-处理cell上按钮事件(弹出警示框,页面跳转等)

一. 目的: 实现UITableViewCell上按钮点击事件可以进行页面跳转. 二. 实现方法: 1. 用协议的方式的实现. 2. 需要自定义UITableViewCell. 三. 代码部分. cell.h中 #import <UIKit/UIKit.h> @protocol SevenProtocolDelegate <NSObject> - (void)sevenProrocolMethod:(UIViewController *)viewController and:(NS

iOS:一个Cell中设置另外一个Cell中的button

场景: 子类化Cell中有button,拥有选中式样,点击第一个Cell中的button后,Cell一中的button获得选中式样,但是当点击Cell二中的button时,Cell一中的button选中式样依然存在,即同时存在两个选中的button. 解决方法: 在子类化的Cell中,定义一个 static UIButton *selectedButton; 必须是 static 静态变量. 然后在点击方法中, - (void)headerButtonClickAction:(UIButton

UITableView (3):显示cell上的菜单

问题:想让用户使用APP时,只要通过一个手指放在APP中一个TableViewcell上,就能在他们原本可选的操作中使用复制/粘贴选项 方案: 在TabView的委托对象上实现下面3个UITableViewDelegate协议方法: tableView:shouldShowMenuForRowAtIndexPath: 返回值为BOOL类型,如果返回YES,iOS将为TableViewCell显示快捷菜单 tableView:canPerformAction:forRowAtIndexPath:w

objc_setAssociatedObject获取cell上button对应所在的行

#import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIButton *btnTest; @end #import "ViewController.h" #import "TestCell.h" #import <objc/runtime.h> static void *btnIndexPathKe

获取cell中的button在整个屏幕上的位置

编写cell中得button点击事件 - (IBAction)showButtonClick:(id)sender { UIButton *button = (UIButton *)sender; UIWindow* window = [UIApplication sharedApplication].keyWindow; CGRect rect1 = [button convertRect:button.frame fromView:self.contentView];     //获取but