views:

42

answers:

2

I need to tell a uitableview to reloadData when something happens on another view (or at least that is what I think I need to do) how do I do it??

the uitableview is just an IBOutlet of a uitableviewcontroller object.

more details: So i have an array of data as kind of a database and a user creates objects to populate the database on view 1 of a tabBar app. view 2 is basically is a view that displays all the objects in the the same "database" array. the array is kept in the app delegate.

The app will show updates on a relaunch in the table view but not on a switch from view 1 to view 2, say after a user creates an object instance in view 1.

EVEN more details!!!

I just noticed that the first time through if you enter in data on view 1 and then go to view 2 the data new data you just added is there but if you go to view 2 before entering any data and then go back to view 1 the UItaableview in view 2 will not update until you relaunch.

Thanks

Nick

A: 

If you have the UITableViewController object, just call

[theTableViewController.tableView reloadData];
KennyTM
i tried doing that in the viewdidload method but it didn't work, maybe I have bigger issues?
nickthedude
`-viewDidLoad` will only be called once and you don't need `-reloadData` in that case. Do you mean `-viewDidAppear:`?
KennyTM
probably, i tried it in viewdidload, viewwillappear, viewdidappear, nothing is working,
nickthedude
@nick: `-viewDidAppear:` with a colon. The colons are significant in ObjC.
KennyTM
+1  A: 

If the controller in tab 2 is a UIViewController with a UITableView property set as an IBOutlet, do the following:

- (void)viewWillAppear:(BOOL)animated 
{
    [self.tableView reloadData];
}

If your view controllers are UITableViewControllers, then they already have tableView properties and perform the above behavior on their own. If you are creating your own tableView property on UITableViewControllers, then you are overriding behavior that is already there and probably breaking functionality.

bstahlhood
dude you are the man, totally effing worked, I was looking at the method you put and I was like yeah i already did that, but then I realized that the animated argument was not there, put that bad boy in and it is the working friggan spectacularly!!! You rock!!!!
nickthedude