indexpath.section和indexpath.row一直为0分别什么时候用

5240人阅读
- (void)viewDidLoad
//给cell加长按手势
UILongPressGestureRecognizer *gestureLongPress = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(gestureLongPress:)];
gestureLongPress.minimumPressDuration =1;
[self.tableV0addGestureRecognizer:gestureLongPress];
[gestureLongPressrelease];
#pragma mark - 长按手势
- (void)gestureLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
& &CGPoint tmpPointTouch = [gestureRecognizer
locationInView:self.tableV0];
& &if (gestureRecognizer.state ==UIGestureRecognizerStateBegan) {
& & & &NSIndexPath *indexPath = [self.tableV0indexPathForRowAtPoint:tmpPointTouch];
& & & &if (indexPath ==
& & & & & & NSLog(@&not tableView&);
& & & & }else{
& & & & & &focusSection = [indexPath
& & & & & &focusRow = [indexPath
&& & & & & &
& & & & & &NSLog(@&%d&,focusSection);
& & & & & &NSLog(@&%d&,focusRow);
&& & & & & &
&& & & & & &
& & & & & &deletebtn.hidden =NO;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:focusRow inSection:focusSection];
[self.tableV0 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:287493次
积分:2852
积分:2852
排名:第9047名
原创:36篇
转载:64篇
评论:21条
(2)(1)(1)(2)(1)(1)(1)(1)(3)(1)(1)(2)(1)(2)(1)(1)(1)(1)(2)(1)(4)(8)(6)(2)(2)(3)(11)(1)(4)(11)(22)最近做tableview的cell倒计时,原来的方案是每次计时触发重新reloadData,导致内存暴涨。故而找了几种直接修改cell中的具体label控件内容的方法。现总结如下:所谓NSIndexPath,主要用来标识cell在列表中的坐标位置,其有两个属性:section、row,section是用来标识cell处于第几个section中,row是用来说明cell在该section中的第几行。1、单击某个cell中的button获取indexPath
一般方式- (void)buttonAction:(UIButton *)sender
UITableViewCell *cell = (UITableViewCell *)[sender superview];
NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
NSLog(@""indexPath is = %i"",indexPath.row);
runtime添加属性方式
//runtime 关联对象
- (UITableViewCell *)tableView:(UITableView *)tableVie cellForRowAtIndexPath:
(NSIndexPath *)indexPath
static NSString *reuseID = @""cellID"";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:reuseID];
if (cell == nil)
cell = [[QuoteManageDataTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
Unbutton *button.......
button.tag = 110;
UIButton *button = (UIButton *)[cell.contentView viewWithTag:110];
//runtime 关联对象
objc_setAssociatedObject(button, @""button"", indexPath, OBJC_ASSOCIATION_ASSIGN);
//事件触发 runtime 获取关联的对象
- (void)buttonAction:(UIButton *)sender
//runtime 获取关联的对象
NSIndexPath * indexPath = objc_getAssociatedObject(sender, @""button"");
NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
NSLog(@""indexPath is = %i"",indexPath.row);
2、已知具体row,获取indexPath
- (void) refreshLessTime
for (int row = 0; row & leftTimeArr. 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];
热点阅读:
小主,按键盘右方向键 → 翻页可以跳过片头呢
本文标题:
原文链接:
和本文相似的内容:
编辑推荐 &&
日,佛山市发生了一起特殊凶杀案:犯罪嫌疑人李善周雇凶两名,将受害者张东成控制后,李善周亲自手持一柄尖刀,对着张东成的下体猛刺,活生生地将张东成的阴茎和你的位置: >
> iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section
在section=10;row=1;的UITableView中,每一个cell都带有一个按钮,例如如下的图片一样
每一个cell中都有一个“进入店铺的按钮”,但是如果我点击相应的cell要进入对应的店铺如何处理呢?
如果用”- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath”这个方法的话会的确可以用“indexPath.section”定位到我点击的是哪一个section,但是会使得整个cell都能点击。如果不介意的话这个方法当然可以,下面来说一下只通过按钮来确定是哪一个section的方法。
首先,你的按钮必须要绑定你的事件,和storyBoard拖个线就行了。
然后一定要在storyBoard仔细观察你的button上面一共有几层才能到你的cell,也就是属一下上面有几个父类才到cell
如图所示,方框里的是button,上面到cell一共有三层。为什么要看有几层,我们来看一下按钮的代码
- (IBAction)enterShopButton:(UIButton *)sender {
UIView *v = [sender superview];//获取父类view
UIView *v1 = [v superview];
UITableViewCell *cell = (UITableViewCell *)[v1 superview];//获取cell
NSIndexPath *indexPathAll = [self.tableView indexPathForCell:cell];//获取cell对应的section
NSLog(@&indexPath:--------%@&,indexPathAll);
首先第一个“v”是获取“View”这一层,然后继续调用superview往上翻(不懂的对照上面的图来看)
“v1”是获取“Content View”这一层,
“cell”就获取到了对应的cell这一层。然后取出cell的路径
path = 2 - 0
代表当前cell所在的section,“0”代表当前cell里的row位置。
再通过“indexPathAll.section”就能获取当前的section了。
个人觉得非常好用,而且很容易理解。
本文永久地址:/3400.html本文出自
,转载时请注明出处及相应链接。
与本文相关的文章indexpath.row返回的什么值_百度知道问题:苹果公司现任CEO是谁?2字正确答案:库克
主题 : [NSIndexPath indexPathForRow:0 inSection:0] 什么意思?
级别: 新手上路
可可豆: 90 CB
威望: 90 点
在线时间: 74(时)
发自: Web Page
来源于&&分类
[NSIndexPath indexPathForRow:0 inSection:0] 什么意思?&&&
[NSIndexPath indexPathForRow:0 inSection:0] 什么意思? 求解!!!
级别: 骑士
UID: 25354
可可豆: 1543 CB
威望: 1511 点
在线时间: 710(时)
发自: Web Page
我在UITableView用到过,可能是指第零组第零行
级别: 新手上路
可可豆: 90 CB
威望: 90 点
在线时间: 74(时)
发自: Web Page
回 1楼(wanghua) 的帖子
刚看代码看晕了,我感觉在此处也就是个初始化把?
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版}

我要回帖

更多关于 indexpath.row nil 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信