There's something I don't understand with tableviews: how to add a new item in a table view.
Here's what I do: when i click on a button "+", the modal controller appears, we enter a new item, and the table view should be edited, with a new item at the bottom. In the rootViewController, I attach the tableWebsites mutable array to the modal viewcontroller, so we have a copy of the mutable array and we can add the new item at the end of this copy:
ModifViewController *addView = [[ModifViewController alloc] initWithNibName:@"ModifViewController" bundle:nil];
addView.tabWebSites = self.tabWebSites;
And finally, in the rootViewController, we say :
[self.tableView reloadData];
So we copied the mutable array in RootView... to be edited in ModifView... but how does the tableview know that the mutable array tableWebsites edited in ModifView... is the one that should "fill" the table view? because we have a tableWebsites in RootView... and another tableWebsites in ModifView... in order to edit it. So i开发者_开发问答 would think that : even if we say "reloadData", it will reload the same mutable array in the RootView.
Do you understand what i mean? i'm sorry if it's a mess, i have trouble to make myself clear ;) Thanks for your answer.
Paul
UITableView objects are actually asking their data sources for the values to display, as well as the number of sections, etc...Sending reloadData
to the table view will make it re-asking these values.
So I think no matter with the array the data source is picking the values from, but these methods should always return the correct value.
Useful links :
Table View programming guide
UITableView class reference
UITableViewDataSource protocol reference
You are using numberOfRowsInSection method. It returns the number of rows.See that method Have you used [tabWebSites count] ? So after you add the value in array and when you again come back to Rootviewcontroller and execute [self.tableView reloadData]. It will execute all the TableView Methods again.
精彩评论