IOS 建立NSIndexpath

 

 

 

 

有时候须要根据tag来获取cell,须要建立NSIndexpath,咱们可能会这么用:数组

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

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


code

 

                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];//刷新表格的某一行
                }
相关文章
相关标签/搜索