簡體   English   中英

如何刷新/重新加載UITableView

[英]How to refresh/reload a UITableView

我有一個表視圖和一個uibutton。

當我單擊uibutton時,它將使用presentModelviewcontroller方法顯示模型視圖控件。

我在presentmodelview中有一個文本字段和“保存”按鈕。

請讓我知道當用戶單擊presentModelview保存按鈕時如何重新加載表視圖

如果您需要刪除presentModalViewController然后重新加載tableView,請使用此方法

[yourTableView reloadData];

在初始視圖的viewWillAppear上。

首先將項目添加到數組,然后重新加載表格視圖。

假設您聲明了所有需要的屬性,包括數據源使用的數組。

@property(nonatomic, retain)NSMutableArray *modalArray;

保存時的IBAction按鈕應包含以下代碼:

//Add the item to the array
[self.modalArray addObject:[NSString stringWithFormat:@"%@",txtField.text]];

//Rest of your code, dismiss the modal view

一旦關閉,您需要重新加載表視圖以顯示保存在模式視圖中的最新值。

[self.yourTableView reloadData];

reloadData將隱式調用數據源方法tableView:cellForRowAtIndexPath:該方法將再次循環該數組,並向您顯示新值。

簡而言之,

YourViewControllerClass * vc = [[YourViewControllerClass alloc]init];
[self presentViewController:vc animated:NO completion:nil];

希望這可以幫助 :)

當您想重新加載tableview時,請使用以下行

[self.tableView reloadData];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM