有時候須要根據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];//刷新表格的某一行 }