IOS學習之——向cell表格裡面填資料
阿新 • • 發佈:2018-12-31
向表格中增加資料
方式一 : reloadData 重新整理 tableView
方式二 : insertRowsAtIndexPath 只更新一部分
注意:沒有多執行緒是第二種方式效能低
//新增城市資料 City *city = [[City alloc]init]; city.name = @"深圳"; city.population = 3400; //應該把城市物件 新增到 城市物件陣列中 [self.allcities addObject:city]; //方式一 // //重新整理 整個 tableView // [self.tableView reloadData]; //方式二 //重新整理 最後一行 保證要插入的資料已經插入到資料陣列中 NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:self.allcities.count - 1 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationLeft];