Correct operation of Table View and Table Detail View
I need a small help. In my project there is a tab bar. On one of the tab bar items there is a navigation controller, on the view there is a table view.
For TableViewController there are the usual codes:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myData count];
}
- (UITableViewC开发者_开发技巧ell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// here the DetailViewController is activated
}
The construction of DetailViewController is similar to the TableViewController. The data related to the selected row of TableView will be the key data for the SQL query, the result of which is then stored in an array. The only difference is that I use this:
viewWillAppear: includes and SQL query, then loads the result into the array sqlQueryResult.
- (void)viewWillDisappear:(BOOL)animated {
while( [sqlQueryResult count] >0 )
[sqlQueryResult removeObjectAtIndex:0];
}
This works the very first time when the table DetailView is shown. However, if we go back to TableView and select a different row, DetailView appears but the followings will not run again (as they did already): numberOfSectionsInTableView: or, tableView:(UITableView *)tableView numberOfRowsInSection: . I read in the docs that there are methods that are called only once - however I haven't seen such remark for these ones.
How can I "reset" the TableView? Or what methods should I call to set the number of its rows/sections?
What you're looking for I believe is:
[self.tableView reloadData];
You basically need to send a 'reloadData' message to your tableView. It will then call your methods again to refresh its contents.
精彩评论