Refresh Container View on Button Press
Asked Answered
P

2

9

I have a UIViewController with a container view which holds a UITableView.

Within the UITableView I have a NSFetchController with NSPredicate that uses variables from the intial UIViewcontroller (I hope your still with me). For one instance that the user changes the container view does not update.

How can I force a reload/update on the container view when this occurs? I looked around but did not see much on this topic.

To be specific I have a UIDatePicker that changes the date on a button. It is this that needs to be updated.

enter image description here

President answered 11/7, 2013 at 19:51 Comment(2)
Do you mean you have a container view that holds a table view controller (rather than just a table view)?Ysabel
yes sorry, my mistake. Updated with a picture.President
Y
15

From the initial UIView controller, you can get a reference to the table view controller with self.childViewControllers[0]. So, you need to do it like this:

UITableViewController *tbc = (UITableViewController *)self.childViewControllers[0];
[tbc.tableView reloadData];
Ysabel answered 11/7, 2013 at 19:59 Comment(2)
thanks for the code but didn;t have any luck getting it working. Don't want to seem stupid but where should it go?President
@AlbaClan, I don't know, it's your app -- I don't really know what you're trying to do. reloadData might not be the right thing, but once you have the reference to the tableViewController, you can do anything you would normally do in that controller.Ysabel
W
0

You wrote that you have UIViewController there and not UITableViewController - if you have UIViewController you have to have a property there. I assume that here everything is ok.. But check.

What I am doing while working with containers views is adding element by:

_someVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SomeVC"];
[self addChildViewController:_someVC];
_someVC.view.frame = _containerView.bounds;
[_containerView addSubview:_someVC.view];
[_someVC didMoveToParentViewController:self];

And not with IB. Hope that helps.

Waltman answered 11/7, 2013 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.