Reload data in UItableview using a button
I want to add a refresh button in UINavigationBar that refreshes the entire table contents. Nothing happens when i click on the refresh button. I searched google and found that reloadData method refresh开发者_如何转开发es the tableview so I tried using it.
- Are you sure your tableView outlet is linked correctly to your tableView property in Interface Builder ?
- Is your internal datasource `refreshed' before you call reloadData?
-[UITableView reloadData]
tells the table view to request again from you the number of rows in the table, and the cells at each section and row. It's up to you to update your internal data structures as appropriate. So in this case, your IBAction
should call your own method to refetch the data from the server.
A few other notes:
- Method names should have leading lowercase.
-initWithContentsOfURL:
is blocking. This can hang your program for a long time. You should be using asynchronous fetching here (generally withNSURLConnection
).
make sure you have the tableView outlet hooked up to the tableView.
精彩评论