IOS 创建NSIndexpath

 

 

 

 

有时候需要根据tag来获取cell,需要创建NSIndexpath,我们可能会这么用:

NSIndexPath *indexPath = [[NSIndexPath alloc] initWithIndex:tag];

没有报错,但很遗憾的是通过这样的indexPath,你是怎么都获取不到cell的!正确的创建方法是:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];


 

                if ([self.dataArray indexOfObject:model] != NSNotFound) {//数组中某一元素在数组中的位置
                    NSInteger inde =[self.dataArray indexOfObject:model] ;
                    NSLog(@"-2---%ld----",inde);
                    model.status = @"1";
                    [self.dataArray replaceObjectAtIndex:inde withObject:model];//替换数组中某一元素的值
                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:inde inSection:0];//创建NSIndexpath
                    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];//刷新表格的某一行
                }

 

posted @ 2019-06-13 14:52  OIMMZC  阅读(778)  评论(0编辑  收藏  举报