1

I have a tabBar application. There are 2 UIViewControllers A and B. UIViewController B has UITableView. I call method in A UIViewController from B UIViewController: [b someMethod:someObject];

Here is code:

-(void) someMethod:someObject
{
  [tableViewDataArray addObject: someObject];
  [tableView reloadData];
}

But UITableView doesn't reload until I switch UIViewController to B; How to reload it without switching? If this possible

Timur Mustafaev
  • 4,869
  • 9
  • 63
  • 109
  • Are you sure the UIViewController B object is not nil inside UIViewController A? This would fail silently. – Wolfgang Schreurs Sep 17 '11 at 19:24
  • `I call method in A UIViewController from B UIViewController: [b someMethod:someObject];` It's not clear what you mean here. You say you call a method in "A", but you're clearly sending a message to "B". It's also not clear what you mean by: `UITableView doesn't reload until I switch UIViewController to B` UIViewController is a class. It doesn't switch to anything. Giving us more sample code would help us a lot. – jemmons Sep 17 '11 at 19:26
  • B UIViewController initialized, i'm sure. I mean i call method in A UIViewController that implemented in B UIViewCOntroller – Timur Mustafaev Sep 17 '11 at 19:30
  • By switching I mean switching tabs in UITabBarController. I've put breakpoint in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath and in [b someMethod:someObject]; Breakpoint in someMethod works immediately. But breakpoint in tableView:cellForRowAtIndexPath works only when i switch UIViewController B with UITabBarItem. – Timur Mustafaev Sep 17 '11 at 19:51
  • Why are you trying to do this? I'm not being snarky; it just might help someone better answer your question if the context is fleshed out a little. – adpalumbo Sep 17 '11 at 20:17
  • I want to add new created cell to dictionary, for reusing it in future. Simple reusing is bad method for me. Because i've got UIProgressView in each cell. And simple cell reuse is mixing UIProgressView values. – Timur Mustafaev Sep 17 '11 at 20:30
  • When i reload my tableView in [someMehod:someObject], i reuse cell. if my dictionary doesn't contain cell, i create new and add it into dictionary – Timur Mustafaev Sep 17 '11 at 20:38

2 Answers2

1

your best solution is to put a button on the toolbar for adding and refreshing and make a function called add() and connect it to the button. and inside there you do :

-(void) add:someObject
{
[tableViewDataArray addObject: someObject];
[tableView reloadData];
}

I was having a similar issue and this actually worked, this should help : How to Reload a UITableView While I am Looking at It

Community
  • 1
  • 1
ahoura
  • 689
  • 1
  • 6
  • 16
0

UITabBarController doesn't load all its tabs' views until they are actually needed, so your table view probably doesn't even exist (i.e. is nil) before you switch to the tab that contains it.

While you could force the view controller to load its view hierarchy by accessing its view property, I wouldn't recommend it. What's the point of reloading an invisible table view anyway?

omz
  • 53,243
  • 5
  • 129
  • 141
  • And in low memory situations, when the other tableView on the other view controller is not visible, the OS may decide to release that other table view – kris Sep 17 '11 at 19:33
  • 1
    B UIViewController and UITableView is not nil. – Timur Mustafaev Sep 17 '11 at 19:41
  • Still, as `cellForRowAtIndexPath:` is only called for visible rows, it makes perfect sense that it isn't called at all if the entire table view is not visible. – omz Sep 17 '11 at 19:52
  • Solve what? I don't really see the problem here, why do you need the table view to load cells when it isn't visible? – omz Sep 17 '11 at 20:20
  • I want to add new created cell to dictionary, for reusing it in future. Simple reusing is bad method for me. Because i've got UIProgressView in each cell. And simple cell reuse is mixing UIProgressView values. – Timur Mustafaev Sep 17 '11 at 20:32
  • When i reload my tableView in [someMehod:someObject], i reuse cell. if my dictionary doesn't contain cell, i create new and add it into dictionary – Timur Mustafaev Sep 17 '11 at 20:38
  • Bad idea. Use the normal reuse mechanism of `UITableView` and simply store the progress values in your dictionary. When you dequeue a cell, simply assign the progress value from the dictionary to the `UIProgressIndicator` in the cell you dequeued. Anything else is a waste of memory. – omz Sep 17 '11 at 20:50
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/3561/discussion-between-timur-mustafaev-and-omz) – Timur Mustafaev Sep 17 '11 at 21:01