Reputation: 8396
I've View Controller
which has a Container View
, and the Container View
is holding inside a UITableView
.so the main class for View Controller
which is MainViewController
and the class for UITableView
is TableViewController
What i have here is that i need to refresh UITableView
in the MainViewController
.
I've found this code in objective-c but i tried converting it into swift but it didn't work :
UITableViewController *tbc = (UITableViewController *)self.childViewControllers[0];
[tbc.tableView reloadData];
Swift code i tried but it didn't work:
var tv : TableViewController = self.childViewControllers[0] as! TableViewController
tv.myTableView.reloadData()
The error I'm getting is this :
Could not cast value of type 'UINavigationController' (0x1950dc0b0) to 'myapp. TableViewController' (0x10021c470).
Upvotes: 2
Views: 8121
Reputation: 8396
In my MainViewController
I've wrote this and also by calling viewWillAppear
it force TableView to reload :
var tv : TableViewController = self.childViewControllers[0] as! TableViewController
tv.mytableview.reloadData()
tv.viewWillAppear(true)
Thanks to everyone who helped
Upvotes: 16