资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

代码拾遗录--轻松获取Cell里的button的indexPath-创新互联

代码拾遗录--轻松获取Cell里的button的indexPath

成都创新互联公司主要业务有网站营销策划、网站设计、做网站、微信公众号开发、小程序开发H5响应式网站、程序开发等业务。一次合作终身朋友,是我们奉行的宗旨;我们不仅仅把客户当客户,还把客户视为我们的合作伙伴,在开展业务的过程中,公司还积累了丰富的行业经验、成都全网营销资源和合作伙伴关系资源,并逐渐建立起规范的客户服务和保障体系。 

 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier from:(UITableView*)table
{
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
   if (self) {
       self.tableView = table;
       [self createUI];
   }
   return self;
}

- (void)createUI
{
   self.backgroundColor = [UIColor purpleColor];
   self.textLabel.font = [UIFont systemFontOfSize:50.0f];

   UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
   button.frame = (CGRect){0,0,60,40};
   button.backgroundColor = [UIColor whiteColor];
   [button addTarget:self action:@selector(clickAction:event:) forControlEvents:UIControlEventTouchUpInside];
   self.accessoryView = button;
}

- (void)clickAction:(UIButton*)sender event:(id)event
{
   NSSet * touches = [event allTouches];
   UITouch * touch = [touches anyObject];
   CGPoint currentTouchPosition = [touch locationInView:self.tableView];

   NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:currentTouchPosition];
   if (indexPath != nil) {
       NSLog(@"%@",indexPath);
   }
}

关键代码 要将table传入cell里面 还有一句  indexPathForRowAtPoint:

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享文章:代码拾遗录--轻松获取Cell里的button的indexPath-创新互联
浏览地址:http://cdkjz.cn/article/gciij.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220