in my iphone app i am adding data to table view on click of button but its not getting updated.It ll update only if i reopen the app.
4 Answers
Use [yourTableView reloadData] to tell the tableview to reload its data and be updated.
5 Comments
JFS
How would that work with table views created in Interface Builder (sorry I'm a beginner)? I've the problem that the row number doesn't update when a row of the table is deleted. Thanks!
AliSoftware
IB or by code, same story. A
UITableView created by instanciating a NIB (and with an IBOutlet variable or property pointing to the instanciated tableview) is just like an UITableView created by code, no difference here. Your problem is elsewhere.JFS
Thanks! There's no problem. I just try to understand. The hint with the IBOutlet is good though.
AliSoftware
Actually, an ivar or
@property annotated with IBOutlet is no different from any other ivar or @property. The IBOutlet keyword (actually #defined to nothing) is just here to let IB know you want to expose this ivar/property in your XIB to be able to connect some object to it, so that when IB instanciates the object, it can affect it to this ivar/property, the same way you would have done it by code. Writing self.tableView = [[UITableView alloc] initWithStyle:...]; is quite the same as creating the tableview via IB and connect it to the tableView IBOutlet property in your XIB.JFS
Thanks for the real good details. I'll try to get that implemented.
Use the [tableView reloadData] method on button click after updating the table view's data source.
So something like this:
-(IBAction) buttonPressed:(id)sender
{
// Update data source of table first
[tableView reloadData]
}
Also check this out: UITableView reload data