麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

外部獲取IndexPath的幾種方式(關(guān)聯(lián)對(duì)象等)

2019-11-09 15:53:54
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一、單擊某個(gè)cell中的button獲取indexPath

1、 一般方式
- (void)buttonAction:(UIButton *)sender { UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview]; NSIndexPath *indexPath = [_tableView indexPathForCell:cell]; NSLog(@"indexPath is = %i",indexPath.row); }
2、runtime添加屬性方式,即關(guān)聯(lián)對(duì)象的方式
//runtime 關(guān)聯(lián)對(duì)象 這種方式首先引入#import <objc/runtime.h> - (UITableViewCell *)tableView:(UITableView *)tableVie cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identiStr = @"cellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identiStr]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identiStr]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, 0, 100, 33); [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; button.tag = 110 + indexPath.row; [cell.contentView addSubview:button]; } UIButton *button = (UIButton *)[cell.contentView viewWithTag:110]; //runtime 關(guān)聯(lián)對(duì)象 objc_setAssociatedObject(button, @"button", indexPath, OBJC_ASSOCIATION_ASSIGN); [button setTitle:dataSource[indexPath.row] forState:UIControlStateNormal]; return cell; } //事件觸發(fā) runtime 獲取關(guān)聯(lián)的對(duì)象 - (void)buttonAction:(UIButton *)sender { //runtime 獲取關(guān)聯(lián)的對(duì)象 UITableViewCell *cell = objc_getAssociatedObject(sender, @"button"); NSIndexPath *indexPath = [_tableView indexPathForCell:cell]; NSLog(@"indexPath is = %ld",indexPath.row); }

二、已知具體row,獲取indexPath

- (void) refreshLessTime{ for (int row = 0; row < leftTimeArr.count; row ++) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem: row inSection:0]; UITableViewCell *cell = (UITableViewCell *)[_tableView cellForRowAtIndexPath:indexPath]; UILabel *remainingTimeLabel = (UILabel *)[[cell.contentView viewWithTag:500] viewWithTag:501]; remainingTimeLabel.text = [leftTimeArr objectAtIndex:indexPath.row]; }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 成人做爽爽爽爽免费国产软件 | 新久草视频| 天天夜夜草 | 综合激情网 | 一级在线视频 | 正在播放91精 | 国产精品99久久99久久久二 | 欧美jizzhd极品欧美 | av在线播放电影 | 国产一区二区三区在线免费 | 欧美城网站地址 | 特色一级黄色片 | 久久恋| 麻豆小视频在线观看 | 韩国草草影院 | 久久激情免费视频 | av在线观| 免费视频www在线观看 | av在线免费网 | 中国久久久| 日本残忍极度灌浣肠视频 | 欧美视频在线一区二区三区 | 青青草国产在线视频 | 国产日本在线播放 | 精品国产91久久久久久久妲己 | 九九精品视频观看 | 久久精品国产99国产精品澳门 | 国产亚洲高清在线精品不卡 | 成人三级电影网站 | 国产一级毛片高清视频完整版 | 色a综合 | av在线日韩| 国产一区免费视频 | 久久影院免费观看 | 8x成人在线电影 | 久久草草影视免费网 | 素人视频在线观看免费 | 成年免费大片黄在线观看岛国 | 最近日本电影hd免费观看 | mmmwww| 亚洲成年人免费网站 |