Linking Storyboards Without UINavigationController - uinavigationcontroller

I have an iOS 6 app that I am updating to work with iOS 7 and to make it use storyboards. I am trying to use multiple storyboards so that I can break my project down into modules for each screen in the app. So far this has worked out fine but now I need to provide a way to navigate between the various storyboards while still making the work like it did in iOS 6 (but with updated artwork).
I don't use UINavigationController in my existing iOS 6 app and I would prefer not to use it as up to now I have been able to navigate back and forth between XIB's using code on UIButton tap gestures. The UINavigationController doesn't make it easy to customise how the navigation buttons look from what I have learned so far about it.
I found this very clean way of moving between view controllers that are on different storyboards https://github.com/rob-brown/RBStoryboardLink by passing the name of the storyboard in as an attribute.
But it only seems to work when UINavigationController is used. I get an error "Push segues can only be used when the source controller is managed by an instance of UINavigationController" without UINavigationController.
Is there a way to navigate between storyboards by only using the above RBStoryboardlink but without the need for UINavigationController?

Push segues can only be used when the source controller is managed by an instance of UINavigationController
This means you are trying to push a view controller to the source while source don't have any navigation controller stack.In that case, you should try to add the instantiated view controller's view as subview to the source view controller's view.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController = [mainStoryboard instantiateInitialViewController];
[self.view addSubview:viewController.view];
or you modally present, that purely depends on your requirement.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController = [mainStoryboard instantiateInitialViewController];
tabBarViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:tabBarViewController animated:NO completion:NULL];

Related

Add a UINavigationController in CCLayer

I am trying to create an app that uses cocos2d for the homescreen, and a UINavigationController for some tables and information. I use this code to try to push a UINavigationController (Settings) into view
UINavigationController *controller = [[UINavigationController alloc] init];
Settings *newTableViewController = [[Settings alloc] init];
[controller pushViewController:newTableViewController animated:YES];
This code is executed in a CCLayer, and Settings is a UINavigationController.
I get this error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
Does this mean that I can't push a NaviagationController into a CCLayer?
Please Help.
You cannot "push view controller to the CCLayer". All that you are doing using cocos2d takes place inside one OpenGL view.
If you really want to do something like this, you can change creation of the application's root view controller. Make your application view controller a subclass of UINavigationController instead of UIViewController, then just get rootViewController from your app delegate and push/pop any other view controller to it whenever you want. Anyway, I don't think, that it is a good idea.
About your exception I assume that your Settings class is a subclass of UINavigationController. All the controllers that you want to push to the navigation controller must be derived from UIViewController, not UINavigationController.

Unable to get html file to display in UIWebView

I am attempting to follow this example: http://howtomakeiphoneapps.com/uiwebview-tutorial/239/
I have added a UIWebView into my view (using Storyboard)... I added the IBOutlet to my .h controller file. (see image at: http://imgur.com/GfUmC). I added a delegate to the view controller like this:
#import <UIKit/UIKit.h>
#interface slWebViewController : UIViewController <UIWebViewDelegate> {
IBOutlet UIWebView *slWebView;
}
#end
Since I'm using XCode 4, I don't know how to set the UIWebView's delegate to the File Owner, which is why I think this is what I'm getting a black screen. I'm missing something, but I don't know what. At this point, I would really, really appreciate any help I can get solving this...
In your Storyboard, right click (or ctrl-click) and drag from your UIWebView to the File's Owner on the left side, and choose "delegate".
Alternatively, select the webView (as in your image). Note the top outlet, "delegate". Drag from there to the File's Owner.
Or you can code it. In viewDidLoad, type "self.sIWebView.delegate = self;"
All of this is assuming that you have your URL request right. In case you don't, here's an example:
NSURL * url = [NSURL URLWithString:#"http://google.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url
cachePolicy: NSURLRequestReloadIgnoringCacheData
timeoutInterval: 10];
[sIWebView loadRequest:request];
EDIT: If you are presenting the webView modally, add this code to the view controller that segues to your webview: -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([segue.identifier isEqualToString:#"SegueIdentifier"]) { WebViewController *webView = segue.destinationViewController; webView.delegate = self; } } You'll need to add an identifier to your segue. Just click on the segue itself, go to the third tab from the right, and type in an identifier.
UPDATE: I've isolated the problem to the webViewConroller.m file. Everything is connected properly. If I place the loadRequest code in the viewController at viewDidLoad, I see Google. If I place the loadRequest code in the "webViewController", and mark the ViewContoller as a custom class of webViewController, I get the black screen. I'm wondering if there isn't a better way to get the UIWebView to display content? I really don't need a controller for the webView, just when the segue for that cell is tapped, display the contents of the UIWebView... not sure I can do it with XCode...

Why is self.navigationController = nil from a method

For some unknown reason I cannot push a view, I will try to explain the best I can but i have alot of complicated views going on, And it would be a nightmare to explain but say I have the following method.
-(void)showDetailView{
DetailViewController *detailView = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
}
Which works and would push the detail view onto the stack, this is on my main view and my main thread.
So in the table view i have a cell with a Subview that then takes its view from another view controller. In that view controller I have more subviews, and say when a user clicks a subview a method is called. Which in turn will call this method on the mainView.
So one would believe that then a new view should get pushed. And the code runs, no errors occur but the view is not changed/switched.
I have tried various method of pushing a view inside the view controller that is it called from. and then just calling a method which is directly connected to the navigation controller to push the views.
A few things to add.
1. I have a IBAaction button that pushes a view (that works fine)
2. I assume its because im through so many views but I'm assuming that if you call push view controller it will push whatever view you pass it.
3. I have checked when the method is called from the main view self.navigationcontroller does not = null.
But if the navigation controller is called through the method call it = null.
So is there anyway to restore the null value of a navigation controller?
Im a little confused on why i cant simply call a method to push a view
Thanks
Its ok I have sorted it now
In terms of how i solved accessing the superior superview to my view is
An ID tag to the views superview which is the cell that my subview is in
id CellController = [self.view.superview.superview nextResponder];
[CellController performSelector:#selector(showDetailView:) withObject:Link];
Then calling a method in my cell which then in turn access its superview
id mainController = [self.view.superview.superview nextResponder];
[mainController performSelector:#selector(showDetailView:) withObject:Link];
Which then the main still retains its navigation controller and then in the show detail method in the main passes the link and pushes the new view.
Basically the total superview of a subview can be no higher then wherever it was created. So the subview in my cell could never access and run anything through my mainView properly, i could stuff but it never performed how it should be. So accessing its highest level superview and then getting that to access its superview as the cell is in my main view then I could run methods correctly.
Hope this makes sense only getting my head around it all.
Thanks to -> How does one access a super's view controller?
For the Id tag bit, not used Id in this way so another things learnt
I just had nearly the same problem today. If the navigation bar is hidden when you push a view, you may have a nil navigation controller. I resolve the problem like this :
self.navigationController.navigationBarHidden = NO; // So the navigation controller is not nil
[self.navigationController pushViewController:articleInfoController animated:YES];

UITableViewController subview: Tell pushViewController to owning UIViewController

I have a UINavigationViewController and inside that I have added a UITableViewController as a subview.
I'd like to be able to tell the UINavigationViewController pushViewController from inside the UITableViewController, but I am unable to retrieve the correct navigationController object.
I have tried some of the methods discussed in this thread, but I cannot get the navigationController for the view.
Is there a way to get a reference for the 'owning' view for a subview?
EDIT: I was able to do this:
[[(MyAppDelegate *)[[UIApplication sharedApplication] delegate] mainViewController].navigationController pushViewController:oOptionsViewController animated:YES];
To make it work. But the issue is just I'd like to do it without necessarily knowing the specific name of the navigationController (say it I have several of these instances, where I use the same class, but they may be used in other navigation controllers..)
I think what you've done there is perfect.
navigationController is an instance-variable, so each controller instance will get its own, and they can be set to different things depending on what navigation element they're added to.
Later,
Blake.

viewDidAppear Not Firing in Tabbarcontroller>NavigationController>UITableView

I currently have a tab bar controller set up with a navigationcontroller on one of the tabs, then I have a UITableView nib set up for that Navigationcontrollers view. All of this has been set up through IB and I want to keep it that way. Kind of like this tutorial http://twilloapp.blogspot.com/2009/05/how-to-embed-navigation-controller.html
now the view loads perfectly when ViewDidLoad is called. But when I then load further views via code IE
MyApp_AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *nav = (UINavigationController *)delegate.controller.selectedViewController;
newViewController = [[newViewController alloc] initWithNibName:#"newView" bundle:nil];
[nav pushViewController:newViewController animated:YES];
//At this point the view works! and loads
If I try to go back with the navigation toolbar it goes back to my previous view fine
Now I need to refresh the tableview when I go back but calling viewDidAppear does not work.
I tried adding UINavigationDelegate to the same ViewController Class as the tableview and then calling - (void)navigationController:(UINavigationController *)navigationController didShowViewController:
But that did not work. I also tried adding the same delegate as the tab bar controller and adding the same navigationController didShowViewController: there but that also failed.
How do I get this table to refresh every time the view loads?
You should not have to call viewDidAppear from your code. Cocoa Touch should do that for you.
Call the table view's reloadData method to get it to refresh its contents.
Found I was missing the Delegate declaration in the Interface file. doh! also I tried that in lots of places it only ended up working when I added it to the NavigationControllers first view (my table view)

Resources