Namburi.Rajesh
Namburi.Rajesh

Reputation: 122

How to refresh/reload a UITableView

I have a table View and a uibutton.

When i click on uibutton, it will display a model view control using presentModelviewcontroller method.

I have a text field and save button in the presentmodelview.

Please let me know how to reload table view when the user click's on presentmodelview save button

Upvotes: 0

Views: 529

Answers (4)

dhaya
dhaya

Reputation: 1522

when you want reload tableview please use below line

[self.tableView reloadData];

Upvotes: 0

Charles D'Monte
Charles D'Monte

Reputation: 372

In a nutshell,

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

Hope this helps :)

Upvotes: 0

Malloc
Malloc

Reputation: 16276

First add the item to the array, then reload your table view.

Assuming you declared all properties needed including the array used by the data source.

@property(nonatomic, retain)NSMutableArray *modalArray;

The IBAction on Save button should include the following code:

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

//Rest of your code, dismiss the modal view

Once dismissed, you need to reload the table view to show up the recent value saved on the modal view.

[self.yourTableView reloadData];

reloadData will call implicitly the data source method tableView:cellForRowAtIndexPath: which will loop the array again and so show you the new value.

Upvotes: 0

Scarlet
Scarlet

Reputation: 11

If you need the presentModalViewController to be removed and then the tableView to be reloaded then use this

[yourTableView reloadData];

on the viewWillAppear of the initial view.

Upvotes: 1

Related Questions