如何刷新/重新加载UITableView

时间:2011-03-02 10:35:06

标签: ios objective-c uitableview

我有一张桌子视图和一个uibutton。

当我点击uibutton时,它会使用presentModelviewcontroller方法显示模型视图控件。

我在presentmodelview中有一个文本字段和保存按钮。

当用户点击presentmodelview保存按钮时,请告诉我如何重新加载表格视图

4 个答案:

答案 0 :(得分:1)

如果您需要删除presentModalViewController,然后重新加载tableView,请使用此

[yourTableView reloadData];

在初始视图的viewWillAppear上。

答案 1 :(得分:0)

首先将项添加到数组中,然后重新加载表视图。

假设您声明了所有需要的属性,包括数据源使用的数组。

@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:,它将再次循环数组,从而显示新值。

答案 2 :(得分:0)

简而言之,

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

希望这会有所帮助:)

答案 3 :(得分:0)

当您想要重新加载tableview时,请使用以下行

[self.tableView reloadData];
相关问题