UINavigationController UIToolBar does not show up in my views - objective-c

My UINavigationController contains a UIToolBar with 3 UIBarBottomItems - It has all been drag/drop designed in the storyboard. I want this UIToolbar to be shared on all my views. I have therefore set checked the "shows toolbar". But when I run it the UIToolBar is empty in all of my views. What could be the reason for this ?

I realize this is an old thread but I've just been struggling with this for a couple hours and finally figured out what was wrong. It was something simple so thought I would share. I was calling [self.navigationController setToolbarHidden:NO]; in viewDidLoad. The problem was that viewDidLoad is called before the view controller is pushed onto the navigationController so self.navigationController is nil. I moved the code to viewWillAppear: method and it worked.

UINavigationController have default toolbar. which you can use. you can use following code
[self.navigationController setToolbarHidden:NO];
in the topmost view controller and
[self setToolbarItems:items];
in all your view controllers, where items is an NSArray of that view controller's toolbar items.

select your initial view controller in the storyboard and embed it in navigation controller.
now all your pages should have the navigation bar.. if u manually dragged dropped the previous bars when u run the program it'll show both...
You'll have to remove the old ones and then modify the new one as required.

Related

Need clarity on if I'm switching View Controllers correctly

I'm making an ipad app which has 11 view controllers in storyboard, one of which is a master view that contains buttons to control which of the other view controllers is displayed as its subview.
Does anybody know for sure if it's ok to use UIViewControllers as subviews of other UIViewControllers, with hard evidence from apple or another source? It has been working flawlessly for me using this method so far:
int nextPage = (method to determine nextPage based on button pressed);
[currentView.view removeFromSuperview];
currentView = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:#"page%i",nextPage]];
[self.view insertSubview:currentView.view atIndex:0];
[currentView.view setFrame:CGRectMake(0, 0, 1024, 768)];
Some people online say that if you are using ios5 or later, it's ok, but others say "NO NEVER DO THIS!!!" even if it's ios5. Others say to use container views, but in every tutorial I've seen to use a container view you just end up inserting the view controller as a subview to the main view anyway using this after you've inserted the child view:
[self.view addSubview:self.currentView];
I am not using a Navigation Controller because they have limited customizability and I do not want any stock tab bars or navigation bars, just all custom buttons.
Thanks in advance!
Yes of course, it's how UINavigationController works and how UITabBarController works. Interface Builder will event set it up for you with a container view.
see Creating Custom Container View Controllers
The takeaway is it's important to handle childViewControllers. This can get a bit tricky, but is important for notifications to propagate correctly.

How to switch views using UIStoryboard and UIViewcontroller

I'm still pretty new to Obj-C and iOS so bear with me. In my app I am trying to implement a share button that brings up a second view in the current view controller. I'm following this tutorial(http://www.youtube.com/watch?v=DZ3SyGInklQ) and I run into a problem where the dev uses initWithNibName and I am using a storyboard. I'm wondering why my second view is not coming up when I press my button. It's probably very obvious but I can't figure it out.
Heres some of my current code:
Menu.h
//Share button
- (IBAction)shareButton:(id)sender;
Menu.M
- (IBAction)shareButton:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MenuStoryboard" bundle:nil];
UIViewController *sharebuttonview = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:#"sharebuttonview"];
[self presentViewController:sharebuttonview animated:YES completion:NULL];
}
First you go into the storyboard and then you connect the Share Button with the View you want to show. After that you name this segue with an Identifier.
In you Menu.M in the IBAction you write:
[self performSegueWithIdentifier:#"mySegueIdentifier" sender:self];
(mySegueIdentifier is the Identifier you used before)
Based on your description of the issue it appears that you may want to do a manual segue, which allows you to open a target view controller from any number of UI controls. The workflow has changed from Xcode 5 compared to prior versions of Xcode. You may want to see my blog post for additional tips but essentially you will want to open your storyboard and do a Ctrl+Drag from one view controller in the document outline view to a second view controller.
Then you will need to name the segue that is created by clicking the Segue in the middle of the gray line connecting the two view controllers and update the segue id in the identity inspector.
In your source view controller you should be able to have any action call [self performSegueWithIdentifier:#"MySegueID"];
Additionally, you can add a prepareForSegue method to the source view controller, which allows you to initialize and pass information to the target view controller.
Apple has a sample project that you can download to see this workflow in detail (MultipeerGroupChat)
Hope this helps.

Always visible UIView

I want to place a UIView that will inform the user what is the status of the app. I want that view to be visible even if the user switches views, same thing as the UINavigationBar is always visible, but I don't want to use that bar, I would like to add another view that will show a message.
How can this be done? I can't add the view to the current view, because it will disappear, if the user changes views.
It should be added to the window? But how? I would then have to resize the views so that my new view can fit, but how?
Thanks.
Create a container view controller and set it as the rootViewController of the apps window.
Inside this container you have your status view, and you also resize the windows real rootViewController to take up the remaining space as a subview. If you are using a standard container view conrtoller (tab, navigation etc) as the root then you can use standard navigation methods and the status view will always be visible
There would be problems if you wanted to present modal views though, since these would go over the top of the status view
In your appDelegate.m add your view as subView of window.
UIView *mainBg = [[UIView alloc] init];
mainBg.frame = newframe;
[self.window addSubview:mainBg];
If you have a UINavigationController you can add your view to its view.
[self.navigationController.view addSubView:yourView];
Presenting modal views would cover the view, as stated in the other answer.

Dismiss popover from a table selection

I'm sorry if this duplicates other threads. I've pored through about a dozen, over several hours, but none seem to quite apply to my situation. Namely;
A button presents a popover
The popover contains a table view, nested inside a navigation controller
The user navigates to the second level of the nav controller (a second tableViewController), then makes a selection
Upon making the selection, the popover should dismiss, and pass back the indexPath.row to the original screen.
Importantly, I'm using storyboards and segues to do this (this may be part of the problem!)
I've tried implementing custom delegate methods to do this, but I'm getting hopelessly tangled up. Mainly because
a) The actual delegate is two levels away, and I'm having trouble conveying this "up the chain", as it were.
b) The [segue destinationViewController] is the navigationController. I'm not sure how to get a hook into the actual tableViews it contains, to retrieve or set properties (such as the delegate)
Does this make any sense to anyone? Reading back, this question is almost as bamboozled as I am. If you can decipher it, and have any advice, I'd be very grateful.
You can get to the actual view controller (which has your table view) using the viewControllers property of your navigation controller (segue.destinationViewController). Once you have a pointer to this view controller, set its delegate. Then in tableView:didSelectRowAtIndexPath, notify the delegate that something was selected, and the delegate can dismiss the popover.
EDIT: This could be in your prepareForSegue:
UINavigationController *navigationController = (UINavigationController *)segue.destinationViewController; // cast the destination to UINavigationController
SpeciesTableViewController *speciesViewController = [navigationController.viewControllers lastObject];
speciesViewController.delegate = self;
Apple docs about the viewControllers property of a UINavigationController:
The view controllers currently on the navigation stack. . . . The root
view controller is at index 0 in the array, the back view controller
is at index n-2, and the top controller is at index n-1, where n is
the number of items in the array.
When using a segue, the root view controller is the only view controller, so lastObject always returns the root view controller.
Now, keep in mind that when you select a species in SpeciesTableViewController, you're triggering a segue, and will have to set the delegate of SpeciesDetailViewController. In SpeciesDetailViewController's didSelectRowForIndexPath you can send a message to the delegate to dismiss the popover.

Preventing the dismissal of a view controller in a segue

I am using StoryBoards and am trying to overlay a View Controller's view on top of another View Controller's view so that the two are visible (the top one has a couple of transparent areas).
If I connect the two together with a modal Segue and then call [self performSegueWithIdentifier:#"showTutorial" sender:nil]; the source view is removed and the destination one is shown. No joy.
If I connect them with a push Segue, calling [self performSegueWithIdentifier:#"showTutorial" sender:nil]; doesn't bring up the new view. Embedding the source view controller in a Navigation Controller brings up the destination view, but also removes the source view. No joy.
Any suggestions?
#Inafziger: I thought I would have been able to do that with a segue, but segues are not the way. Also, as I wanted to keep working with the Storyboard and avoid making a new nib file from scratch, here's what I did:
tutorialView = [self.storyboard instantiateViewControllerWithIdentifier:#"Tutorial"];
[self.view addSubview:tutorialView.view];
Then in the Storyboard, write "Tutorial" in the ViewController's Identifier field.