I've noticed somthing interesting when using segues and I do not know why it happens. If someone could explain that would be great.
I am using a Storyboard for the first time and hooked up a number of segues. I named the segues and used the prepareForSegue method. What I am trying to do is the following.
The HomeViewController in my navigation stack conforms to a delegate. When this degelate method is called it checks to see if the next view FeedViewController in the navigation stack has been loaded. If it has, then is reloads the tableView (feedsTableView) on this view. Here is the delegate call back method.
func floDataHanlderDidFinishLoading(dataHandler : FLODataHandler) -> ()
{
if(self.feedViewController!.feedsTableView != nil)
{
println("The reloads feedsTableView is called")
self.feedViewController!.feedsTableView.reloadData()
}
}
When I am using the prepareForSegue method, the if (self.feedViewController!.feedsTableView != nil) is never satisfied even if FeedViewController has been loaded. However if I use a presentViewController method that's called when a button is pressed, if (self.feedViewController!.feedsTableView != nil) is satisfied and feedsTableView gets reloaded.
Here is my prepareForSegue method.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "FeedViewSegue"
{
println("Segue == FeedViewSegue")
if let feedVC = self.storyboard!.instantiateViewControllerWithIdentifier("FeedViewController") as? FeedViewController
{
println("If let called")
self.feedViewController = feedVC
}
}
}
Here is the method called when I press a button.
@IBAction func buttonTest(sender: AnyObject)
{
/
let feedVC = self.storyboard!.instantiateViewControllerWithIdentifier("FeedViewController") as! FeedViewController
self.feedViewController = feedVC
self.navigationController!.pushViewController(self.feedViewController!, animated: true)
}
Is there some fundamental difference between prepareForSegue and presentViewController that does not allow a view to be instantiated? Why would if (self.feedViewController!.feedsTableView != nil) not be satisfied when using prepareForSegue when in that method I have the same code that used in the method with the button press?
Take care,
Jon