How do I get toolbars on UISplitView detail & root views? - toolbar

I'm porting my iPhone app to iPad. I have a bunch of detail views that derive from UIViewController and implement UITableViewDelegate. (Basically TableViews but not derived as such). The old app used TabBar, but now I'd like to use SplitView with toolbars on the Detail and Master views. How do I enable a toolbar on my UIViewController inside a UISplitViewController? I'm not using Interface Builder here, just code.
#interface HeadlineViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *tableView;
NSMutableArray *bullIds;
UIActivityIndicatorView *prog;
}
Thanks,

Related

Linking Storyboards Without 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];

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.

Interface Builder Outlets. Where can I find them?

I can create an Outlet from a ViewController to a View by Ctrl Drag between viewcontroller bar button and the view.
It appears in the context view of the ViewController Bar button.
Where does the outlet created like this appear in code? (or doesn't it?).
The problem I am having is that when I make an Outlet from a view to its controller I sometimes (frequently?) find the pop up choice does not include my View. In other words if I made a view called picView I should see picView as a choice along with view but I only see view.
Later, I find my delegate ViewController methods will not run. When I go back to make the link again, I find mysteriously that my view is now an option and that fixes the issue.
Here are two pictures that illustrate the issue.
Here there is no link available
Here there is a link available
Having gone through the process of creating an App specially to illustrate this point I have discovered that I was looking the wrong way round. Rather than Interface Builder Creating the Outlet I have to put it into the ViewController and then IB can use it to make the link.
This is achieved when I put the outlet into the interface of the ViewController.m file illustrated below. At that moment, the link appears in IB.
//
// SecondViewController.m
// Empty Test
//
// Created by Brian Lockwood on 07/09/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "SecondViewController.h"
#import "PicView.h"
#interface SecondViewController() <PicViewDataSourceDelegate>
#property (nonatomic, weak) IBOutlet PicView *picView; //<<<<<<<<< this line here
#end

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...

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