2

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 4

5

Use [yourTableView reloadData] to tell the tableview to reload its data and be updated.

Sign up to request clarification or add additional context in comments.

5 Comments

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!
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.
Thanks! There's no problem. I just try to understand. The hint with the IBOutlet is good though.
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.
Thanks for the real good details. I'll try to get that implemented.
2

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

Comments

1

try [tableview reloadData]

in wiewWillApear method

Comments

1

Preview Controller to reload its data from its data source.

- (void) reloadData

The display is recomputed only if the current preview item has changed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.