Xcode Navigation Bar Goes under ScrollView? - xcode

Design mode everything is fine but in live Navigation Bar goes under the ScrollView How am I gonna solve this problem ? Please help

Again, without seeing any code at all it is hard to say, but I believe that the navigationBar isn't displaying at all. If you're presenting the UIViewController directly from another view, you're not instantiating the UINavigationController it is embedded in.
A solution would be to either create a segue in your storyboard from your presenting view to the UINavigationController, or add a storyboardId to the UINavigationController and instantiating as:
let nav = storyboard.instantiateViewControllerWithIdentifier("STORYBOARD_ID_HERE") as! UINavigationController
presentViewController(nav, animated: true, completion: nil)
If you can show some code on how the view is presented you'll receive better help, since it's impossible to know exactly what is wrong based on just one image.

Related

Setting maximum height for NSScrollView inside NSMenuItem

i am currently working on a menu bar application for OS X. I want do display some data in a NSTableView within the menu. I already managed to set the view of the first NSMenuItem to my NSScrollView.
The problem is that i don't know how to set the maximum height for the NSScrollView. I want something similar to the Shazam or Adobe Creative Cloud app: A small menu with a TableView inside it that scrolls but doesn't fill the entire height of the screen.
Here is what i currently have:
The way it works now is that the menu automatically fills the entire screen depending on how much data i put into the TableView.
Here is a screenshot of the way the Shazam app does it:
They display lots of information inside the table but restricted the NScrollView to have a fixed height.
I don't think this is hard to do but i don't know where to look for the option.
Any help would be really appreciated :)
Regards,
Timo
I finally figured it out! I assigned the wrong view to the NSMenuItem.
Now i have two outlets inside my AppDelegate:
#IBOutlet weak var myMenuItem: NSMenuItem!
#IBOutlet weak var myScrollView: NSScrollView!
Inside applicationDidFinishLaunching() i assign the NSScrollView to the view property of the NSMenuItem:
func applicationDidFinishLaunching(aNotification: NSNotification) {
...
self.myMenuItem.view = myScrollView
...
}
The problem i used to have that i set the menu items view to the NSTableView directly, not to the NSScrollView. Everything works fine now.
Thats what the result is looking now:
Exactly what i wanted :)
Regards,
Timo

CustomViewController's view's layout becomes wrong when added as subview

I have created a CustomViewController and layed it out in interface builder. Then I am all set to use the CustomViewController's view as a subview in another viewcontroller but when I add it to the other viewcontroller the layout of the custom uivewcontroller becomes wrong.
What can cause this? What is the propper way to do this?
The whole project can be found here https://github.com/agustr/STHLMPubCrawl just download and run (in an iphone 5 simulator). If there is any question about how it should look you can just move the initial view pointer to the 'place view controller cene'
this is the code:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("GPPlaceViewController") as? GPPlaceViewController
if vc != nil{
vc?.view.layer.borderWidth = 4
vc?.view.layer.borderColor = UIColor.redColor().CGColor
self.GPPlaceView.layer.borderColor = UIColor.yellowColor().CGColor
self.GPPlaceView.layer.borderWidth = 2
vc?.view.frame.size = self.GPPlaceView.frame.size
self.GPPlaceView.addSubview(vc!.view)
}
else {
print("could not load GPPlacePageViewController from storyboard")
}
Any help is welcome.
I am unsure if this method of adding a VC's view to another view is wrong or outdated but I seem to remember it working at some point. I contacted apple and they told me to use a ContainerView. It is supposedly explained in detail in this talk 'Implementing UIViewController Containment' https://developer.apple.com/videos/wwdc/2011/.
The biggest problem I had when using the containment View was that you can not drag the segue in interface builder but you have to right click or controll click to point the segue to the appropriate place. Then you can treat that segue as any other in your parent viewcontroller that is to say the viewcontroller that contains the container view.

iOS8 Swift: Navigation and Tool Bars don't show up

NavigationBar and ToolBar are not showing in the simulator. I went through similar questions posted in this forum and included what I learnt from the answers. Still I'm unable to figure out why the bars are not shown.
I also included the following lines to the viewWillAppear()
//Show toolbar and navbar
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationController?.setToolbarHidden(false, animated: true)
Below is the screenshot of my storyboard.
The simulator screenshot appears like
I reach this view controller from a TableViewController (which is embedded in TabBarController) programmatically, with the following code
var nextController = ImagePickViewController()
nextController = self.storyboard?.instantiateViewControllerWithIdentifier("ImagePicker") as! ImagePickViewController
self.presentViewController(nextController, animated: true, completion: nil)
Any help is much appreciated. Please let me know if additional information is required.
Thanks in advance
Hari
Thank you James from Udacity. Posting his diagnosis.
The toolbars didn't show up because I used presentViewController. So the embedded navigation controller was bypassed and the ImagePickViewController was presented directly.
Solution is to start the navigation controller using the segueIdentifier.
I added a segue from my TableViewController to the Navigation Controller (of the ImagePickViewController). In the attribute inspector for this segue, I set the Identifier as "startImagePicker". In the TableViewController code, I start the ImagePickViewController by calling performSegueWithIdentifier -
self.performSegueWithIdentifier("startImagePicker", sender: self)
Thanks
Hari

How I can display another (change) ViewController when I press a button

in my xcode storyboard I have the standard viewController in which I have placed one Button with a Action Outlet.
I tried with an .xib which doesn't load. Further, I tried with an second ViewController in the Storyboard and a custom segue, but this also failed.
There is something I did wrong. Can anybody help me please?
If you are using Segues, you dont need to create a ViewController and try to display it this way. Just give a (unqiue) name to your ViewController (for Example if you dont want to use a "NavigationController" you should use "Modal" as Type. You should add a ViewController Class for each ViewController in Storyboard too.
So connect ViewController1 with your second View Controller and give them a name "loginModal".
Then in your IBAction, you can use:
self.performSegueWithIdentifier("loginModal", sender: self)
That should be all. If you want to send data between ViewControllers, you should use prepareForSegue. Check out my answer here, youll find more information about sending data with segues.
Sending data with Segue with Swift
You can try like this one
Put this code inside #IBAction button.
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let loginViewController = storyBoard.instantiateViewControllerWithIdentifier("LoginView") as loginViewController
self.presentViewController(loginViewController, animated:true, completion:nil)
Don't forget to set identifier's name in loginViewController.

Keep leftBarButtonItems on new UIViewcontroller when pushed

I have a UIViewController embedded in a UINavigationController. The rootViewController now contains already some buttons as leftBarButtonItems.
Now when I push a new UIViewController on top of the UINavigationController I want the new UIViewController to keep the existing leftBarButtonItems extended with the Back-Button.
Right now the situations is as follows: When I push the new UIViewController then the existing leftBarButtonItems disappear and only the Back-Button is visible.
Each UIViewController has it's own "navigationItem" property, which acts as the navigation bar representation for that viewcontroller. When you add buttons to the navigationItem of a particular UIViewController they are limited in scope to the viewcontroller to which they were added, and they don't persist into other viewcontrollers.
Basically, you'll have to add the buttons to the navigationItem of each viewcontroller as it loads. You can make this simpler by writing adding a method to do this work to a class other than your UIViewControllers. What happens when you touch each button might be viewcontroller specific though, so you'll have to think through how touch actions will be fed back to the relevant viewcontroller. Perhaps introduce some kind of NavigationBarDelegate protocol or something?
I found what seems like a hacky way to get around this when pushing multiple instances of the same view controller on to a detail view controller which I assume would work similarly. Before pushing the new view controller I used this: (browser is my new view controller)
self.browser.navigationItem setLeftBarButtonItem:self.detailViewController.navigationItem.leftBarButtonItem animated:YES]; // Sets popover view controller button.
[self.detailViewController.navigationController pushViewController:self.browser animated:YES];
This probably isn't a good way to do it but it seems to work in my situation.

Resources