Navigation Bar Layout Issue on Tab Bar Controller + Navigation Controller - xcode

I've followed a how-to to create a simple Tab bar controller with a navigation controller in the first tab. Until here all is working correctly, expect a strange issue on the layout.
When the app starts the first time, the Navigation Bar on the top of the first loaded nib is a little outside of the view. I cannot figure out why this happen. In the first view there is a button "Add new System" that opens a modal view. If I press this button and the modal view appears and then I dismiss the modal going back to the initial view, then the Navigation bar at the top is placed/refreshed correctly. The same happens if I press the second TAB (it's a simple nib without Navigation controller for now) and then back to the first TAB, the Navigation bar is placed in the correct position.
Here a screenshot on the first startup:
And here when I press the modal view or the second TAB and then back to the first view:
The code is quit simple following one of the numerous tutorials on the net. I'm NOT using storyboard. Only customization was adding the buttons on the top of the Navigation Bar:
UIImage *editbuttonImage = [UIImage imageNamed:#"edit_pressed.png"];
UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
[editButton setBackgroundImage:editbuttonImage forState:UIControlStateNormal];
editButton.frame = CGRectMake(0, 0, editbuttonImage.size.width, editbuttonImage.size.height);
[editButton addTarget:self action:#selector(leaveEditMode)
forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:editButton];
[editButton release];
[editbuttonImage release];
No other modifications were made. The nib was used before in a single view. Then I've tried to insert it into a TAB Controller + Navigation Controller.
I could post the whole code in case it's needed. Under Select System there is a Table View, in these pictures empty, also not shown.
Thank's for the help!
Simon

I've solved the issue myself. On startup I've setup to hide the status bar and shown it again in the app delegate. The directive used :
[[UIApplication sharedApplication] setStatusBarHidden:NO];
was after adding the navController as subview. Also the Navigation controller BAR was not out of the view, simply under the status bar.
Hope this helps someone :)
Cheers, Simon

Related

Is there a way to enable the bottom toolbar in a Collection View Controller?

I made and implemented a collection view controller, and now I wish to add a bottom tool bar for navigation purposes. Under the Simulated Metrics tab in the Collection View Controller, I have enabled the bottom toolbar, and it shows up in the storyboard, and I am able to edit and interact with it.
When I run the app in the iPad simulator, the bottom toolbar does not appear. Is there some setting that I am missing that causes it to show in the storyboard and not in the app?
Any suggestions would be appreciated.
You can embed the UIViewController inside a UINavigationController. In the Storyboard, set the Simulated Metrics for Bottom Bar to one of the Toolbar options on the UINavigationController. You will then notice the Toolbar on the bottom of the UICollectionViewController.
I have done this using Xcode 6.3.2.
I had the same problem in Interface Builder.
Adding the toolbar programmatically works fine, though:
// viewWillAppear:
// set up toolbar
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height-44, self.view.bounds.size.width, 44)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:toolbar];
// instantiate spacer, middleItem
toolbar.items = #[spacer, middleItem, spacer];

Dismissing MWPhotoBrowser View controller Modally in Split View

Ran into a snag and hoping for some insight here.
Overview: Universal app. The iPhone portion works great. The iPad portion has a split view controller. The master is a table view (left side) where the user selects a row and displays its detail (right side). Pretty standard stuff.
I’m using Xcode version 4.4.1 and my project is using Core Data, Storyboards and ARC.
DetailViewController: On the detail is a button that brings up another table view (within the detail) of user notes by date with a custom view. Each note can have an image associated with it. If a note has an image then a button with its photo icon is shown.
Example screenshot up to this point:
MWPhotoBrowser: When the button of the photo icon is pressed I call MWPhotoBrowser (a wonderful library to show images in a standard way) to display the image or images. Single tap shows the one selected image, a double tap shows all images on the current table with the one chosen being viewed first. The image is displayed full screen.
To show the photo browser I use this code:
// Create the browser view.
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
// Set browser options.
browser.wantsFullScreenLayout = YES;
browser.displayActionButton = YES;
[browser setInitialPageIndex:self.buttonRow];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];
[self presentModalViewController:navController animated:YES];
The navController allows me to include a navigation controller with a “Done” button which calls doneButtonPressed.
Issue: All of the above works well until I press the “Done” button. The full screen photo browser dismisses properly. Unfortunately, the table view on the right side from where the user pressed the photo icon button is now gone (black). I thought the NotesViewController (right side) would remain there after photo browser was dismissed modally. Does calling a model view controller in a split view cause the other view controllers to be deleted?
Example screenshot showing problem:
The stacks on the detail view controller (right side) should be DetailViewController > NotesViewController > then call MWPhotoBrowser modally. After the photo browser is dismissed my self.navigationController.viewControllers.count equals 1 and I was expecting it to be 2.
Here’s the code that dismisses the MWPhotoBrowser:
- (void)doneButtonPressed:(id)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self dismissViewControllerAnimated:YES completion:nil];
}
.
.
.
Hope someone can help me wrap my head around this.
As always, any help is greatly appreciated. Thanks!
I resolved my issue within the NoteViewController (the area turning black after the MWPhotoBrowser was dismissed).
Within viewWillAppear I was setting my tableview to nil (to prevent cell overwrap) and reloading my table data.
self.tableView = nil;
[self.tableView reloadData];
This works fine for the iPhone and when not returning from the MWPhotoBrowser’s full screen display on the iPad. For some reason that I do not understand, the above code causes the issue. I added additional logic to check if I’m returning from the full screen display and now all is fine. I’ll look into it more when time permits.

Configuring the backBarButtonItem of a View Controller's Navigation Item in a Storyboard

It's easy enough to drag and drop bar button items onto a view controller's navigation bar in a storyboard in Interface Builder. In this way, you can set the leftBarButtonItem and rightBarButtonItem outlets of the view controller's navigation item. But there's also a backBarButtonItem outlet, and it's not obvious at all how to set it. How can I set a custom back bar button item using Interface Builder?
Select the view controller whose navigation items you want to change. The black bar displaying the identity of the view controller changes to an iconified tray of its referenced objects.
Drag and drop a bar button item from the object library onto the tray.
Right-click on the view controller's navigation item in the main object tray on the left-hand side. Wire up the newly added button as the navigation item's backBarButtonItem outlet.
Select the bar button and configure it in any way you choose with the Attributes Inspector.
As #wcochran noted above, when working with viewControllers pushed onto a navigationController's stack, the backBarButtonItem outlet is already wired and can't be changed. Furthermore, selecting the child VC's navigationItem and changing the Back Button text in IB doesn't do what you would expect.
Now you might think that replacing the child VC's backBarButtonItem would solve the problem, but it doesn't. Confusingly, if you want to set the title of the back button of a child VC, you have to set the back button title of its parent (!), like so:
- (void)viewWillAppear:(BOOL)animated // in the parent VC!
{
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
}
This won't do anything on the parent VC. In fact, if the parent is the navigationController's RootViewController, there won't be a back button at all. But the child will inherit (or pick up) the back button you've created.
This only applies to the immediate child VC, so if you want to maintain the label down through the navigationController's stack you need to set it on each parent.
Thanks to #wiliz in #iphonedev for explaining this to me.
As #AdamBlock noted above, you have to set things right in the parent VC.
He shows how to do this programmatically. It is also possible to do this in interface builder.
Select the parent VC
Select the navigation Item
Open the Attributes inspector
Set the title for the Back Button.
In Interface Builder, you can change the Navigation Item back button's title.
Programmatically, you can set a custom back button in your view controller's viewDidLoad method. In this example we set the button's image to an image named "customImage.png":
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Custom" style:UIBarButtonItemStyleBordered target:self action:nil];
// Set custom image here
backButton.image = [UIImage imageNamed:#"customImage.png"];
self.navigationItem.backBarButtonItem = backButton;
}

How to add a bar button item in interface builder?

I am really new to iPhone development and I need help setting up my views.
I have a view that is named FirstViewController.xib and a controller class for this view.
In my MainWindox.xib I have setup a root controller with a moveToNextView function that is connected to the options bar button item.
So when I click on this item the current view switches to the first view and I am able to swticht back. That works fine so far.
The navigation bar at the top of the screen from the MainWindow.xib is displayed in the first view, too. But when I open FirstViewController.xib there isn't any navigation bar defined (but on build&run it is displayed).
This is a problem for me because I want to add a save bar item to the first view. How do I solve that?
Assuming you have a UIViewController (or UIViewController subclass) that is a child of a UINavigationController. Note, I'm using storyboards so your results may vary when using xibs.
If you do not see a UINavigationBar on the interface, try manually changing the simulated metrics.
Drag a Navigation Item onto the view (anywhere). You should now have a place to enter the title in the interface builder.
Now you can drag Bar Button Items onto the nav bar.
You have to do it from code. Add to your FirstViewController class viewDidLoad method:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Save" style:UIBarButtonItemStyleDone target:self action:#selector(doSave:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
Just drag a bar button item onto your nav bar in Interface Builder. Xcode automatically wires it up then you can use it like anything else...

How to create a window like the e-mail app that pops up

I want to create a window that pops up like in the email app when you hit New Email.
Does anyone has a good tutorial or sample code of how to do this?
This is the screen I want:
Basically it looks like a view controller shown modally with modalPresentationStyle set to UIModalPresentationPageSheet:
SomeViewController *vc = [[SomeViewController alloc]
initWithNibName:#"SomeViewController" bundle:nil];
vc.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:vc animated:YES];
[vc release];
On the view controller, at the top is a UIToolbar and the content underneath can be shown in several ways including a UITableView.
In portrait, the modal view will be the full width of the screen.
It's a modal view controller with style as pagesheet.
You have to present whatever you want as a modal view controller after setting it's modal style.

Resources