最近的項(xiàng)目中遇到很多信息編輯的東西,大家都知道需要將編輯頁的信息回傳到顯示頁。我這里是用一個block去傳遞這些信息的。信息傳遞完成,顯示在tableView的Cell上。大概是這個樣子
if (indexPath.row == 2) {
ZMInputViewController *vc = [[ZMInputViewController alloc]init];
vc.block = ^(NSString *result) {
ZMEditResumeTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.content.text = result;
};
[self.navigationController pushViewController:vc animated:YES];
}
這樣做的話,當(dāng)cell比較少的時候是不會出現(xiàn)問題的,因?yàn)椴粫霈F(xiàn)cell的復(fù)用。當(dāng)cell比較多時,就會出現(xiàn)滑動,問題消失。解決這個問題,要從數(shù)據(jù)源上著手。大概是這個樣子
ZMInputViewController *vc = [[ZMInputViewController alloc]init];
vc.block = ^(NSString *result) {
[_conentArray replaceObjectAtIndex:indexPath.row withObject:result];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
};
[self.navigationController pushViewController:vc animated:YES];
剛開始在寫東西,有些粗糙,歡迎同行提問,指教