IOS 创建NSIndexpath

匿名 (未验证) 提交于 2019-12-02 23:42:01

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

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

没有报错,但很遗憾的是通过这样的indexPath,你是怎么都获取不到cell的!正确的创建方法是:



                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];//刷新表格的某一行                 } 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!