[英](iphone) how to update only one row in tableview
我哈瓦一個tableview
,我會UPDATA中的數據tableview
。它收到DATAS每隔一秒,當接收數據時,它會在一列替換舊數據。 我喜歡這樣:收到數據后,我打電話
[m_tableView reloadData];
因此,它將調用
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ }
所以我將以這種方法更改特定的行數據,但是如何設置row index
?
你有沒有嘗試過
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
迅速
func reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)
這將允許您重新加載單行。
reloadData
方法重新加載整個表
據我了解,將為每個在調用ReloadData
時可見的UITableViewCell
調用此方法。
如果您更新了基礎datasource
,則包含數據的單元格將被更新。
只需將行分配為整數,就可以從該方法訪問它。
NSInteger row = [indexPath row];
如果您嘗試重新加載特定行
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
從蘋果文檔
參數indexPaths NSIndexPath對象的數組,標識要重新加載的行。 animation一個常數,指示如何對重新加載進行動畫處理,例如淡出或從底部滑出。 有關這些常量的說明,請參見“表格單元格插入和刪除動畫”。 動畫常數會影響新舊行的滑動方向。 例如,如果動畫常量為UITableViewRowAnimationRight,則舊行向右滑動,而新單元格從右滑動。
用這種方法
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ }
每當調用reloadData方法時,您都可以編寫此代碼以僅更新特定行。 像這樣,
if(indexPath.row==2){
cell.textLabel.text=@"New updated Value";
}
每次只會更新第三行。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.