Trouble with creating a popover withs storyboard in Xcode - ios

I cannot create a popover with storyboard.
The settings are as follows:
The github repo: https://github.com/li354886/iOSProjects/tree/v1.1/testPopOver
I viewed this video: https://www.youtube.com/watch?v=j5XFMpXLwZQ
The popover view controller just behaves as modal.

Make sure that your app is Universal. You won't see any popovers, by default, on an iPhone-only app. (You can see them in iOS 8, with some extra work, but by default you won't.)

Related

Window's root view controller is not Split view controller

I am trying to modify my existing app to use a split view controller. I've followed the sample master/detail project structure by adding a split view controller into my storyboard, made it the initial view controller and everything seemed to be working fine, until I tried to run the app in an iOS 7 simulator. All of a sudden when I hit my breakpoint in application: didFinishLaunchingWithOptions self.window.rootViewController is now the type of my master view controller, not the split view controller itself.
I thought maybe then I just need to get the split view controller off of the root view itself and tried rootViewController.splitViewController but that is nil. I must have missed some set up step in enabling this split view controller, but I have no idea what it was.
It is because UISplitViewController isn't supported in iPhone in iOS7, only in iPad.
If you run your code in iPad iOS7 you will see your UISplitViewController.
Only in iOS8 Apple added support for iPhone as well.
So this ended up being a pretty obscure issue. It seemed to be caused by the way that the iOS 8 SDK and Xcode 6 handle storyboards and size classes. I intend to file a bug report with apple but the repro steps to get this to present are simple:
Create a new master/detail application
Set deployment target to below 8.0 (7/7.1 works)
Change application type from "Universal" to "iPad"
You have to comment out this line from the generated app delegate, it will crash in an iOS 7 target:
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
Run on iPad simulator for iOS 7.1
The fix to this issue is to disable size classes on the storyboard. I theorize that the way that Xcode 6 and the iOS 8 SDK are handling size classes for iPad versus universal app builds causes this to not work on iOS 7 targets, but turning off size classes fixes the issue.

How do I use popover segues with a universal storyboard on iOS 7?

I'm in the process of moving from hard-coded layouts to the new universal storyboard system available in Xcode 6. It's great to be able to create one storyboard that, through the magic of auto-layout, will work on both the iPhone and the iPad. And my understanding is that universal storyboards are backwards-compatible with iOS 7.
However, I'm running into a problem using popover segues. On iOS 8, the new 'Present as Popover' segue will display as a popover on an iPad interface and as a modal view controller on an iPhone interface. This is exactly the behavior I want, but when I run my universal storyboard on iOS 7, the app crashes whenever I attempt a popover segue. Here's the error message I get:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[UIPopoverController initWithContentViewController:] called when not
running under UIUserInterfaceIdiomPad.'
This is a bit annoying, as I don't want to have to resort to separate storyboards for each UI idiom.
It looks like these are my choices:
Create a subclass of UIStoryboardSegue that will show a popover on iPad and a modal view on iPhone. This requires manually changing the class of all popover segues in my app.
Create two segues out of every bar button item, table cell, etc. - one that's a pure 'Popover' segue and one that's a pure 'Modal' segue. In this case, I'll be unable to just control-drag to the next screen and will have to create custom action methods that will invoke the right segue based on the current UI idiom.
Abandon universal storyboards and create device-specific storyboards until I can require iOS 8 from my users.
None of these are great alternatives, so I was wondering: do I have any other options? Am I missing any problems with my proposed solutions?
Xcode 6 supports unified storyboards. A storyboard can add or remove views and layout constraints based on the size class that the view controller is displayed in. Rather than maintaining two separate (but similar) storyboards, you can make a single storyboard for multiple size classes.
But Size classes are based on UITraitCollection which is supported on iOS8. That's why it's crashing on iOS7.
I ended up making a modal segue and checking in code to see if it was on a iPhone with iOS 7. I then use performWithSegue to pick which segue should be taken. iOS 8 can handle the popover code but iOS 7 has issues.
Seems Like You are trying to present your view modally if device is iPhone and as Popover if the device is iPad..
To produce that the easiest way would be to check the InterfaceIdiom when the event occurs(like button click) and conditionally using appropriate approach.
-(IBAction)btnClicked:(id)sender{
if([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad){
//your popover code..
}else{
//your present modaly code...
}
}

Where is UISplitViewController in universal App?

I made an application for the iPhone and now I want to make a port for the iPad. So I changed the setting to Universal. I would like to use for the iPad version the Split View, but I do not see it anywhere (I use Storyboard). Please help. Thanks
Check the object library in the lower-right corner:
After you switch the app to universal you have to create a separate iPad storyboard. Goto New File and under User Interface choose storyboard. When you click next it will ask you device family, choose iPad. After you create the storyboard and go there you will see the Split View Controller as in #Aaron Brager answer.

unable to embed Navigation Controller from storyboard in iOS

![enter image description here][1]How to embed in Navigation Controller as I am having two View Controllers with one of them as RootViewController and when I go to editor--->Embed-in--->no options are usable/Selectable !! Please suggest me the reason as I have used Navigation Controller earlier in previous sample app and it was working fine .
Please help on this!! Thanks in advance
Your screen shot shows a nib file, not a storyboard. You need to create a storyboard and then you will be able to embed your view controller.
You will also need to change your project settings to require iOS 6 as a minimum Upgraded app to iOS 7 - error "Auto Layout on iOS Versions prior to 6.0" (but want iOS 7 not older)
Also make sure you change your project to refer to your main storyboard rather than an xib How to convert a NIB-based project to a Storyboard-based?

Create universal app using iOS StoryBoard that have different UI

I'm new with iOS and yesterday i learnt about storyboard. it works great. i refer to this link. I tried to create iPhone apps with a storyboard.
But now i want to create an universal apps, that means for iPhone and iPad. but also using the storyboard. lets say if i have the same UI, that wont be an issue. Same UI means, my iPhone UI using tab bar controller, my iPad also use a tab bar controller. I just need to point to the same class, and the result will be the same. Now, i want have a different UI. my iPhone will use a tab bar, but my iPad will use a split view.
here is my question :
is that possible to do that with device target universal? i mean iPhone with tab bar, iPad with split view.
if yes, how can i know which device is running? either i choose iPad or iPhone. How can i know i run on iPhone/iPad? what should I validate in the appdelegate?
For ipad storyboard, i drag a split view controller but i can't see any master detail whenever i run the apps. how can it be like that?
thanks. :)
If you create a Universal application (an application that supports both iPhone and iPad), Xcode will by default give you two Storyboards - one for iPhone, one for iPad. Under your target's settings you'll see a place where you can configure which Storyboard presents the main interface - you can set this separately for iPhone and iPad:
The OS will take care of loading the correct Storyboard for you.
If you want to detect in code whether you're running on an iPhone or iPad, you can use USER_INTERFACE_IDIOM(). For example:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
There's also UIUserInterfaceIdiomPad for iPad.

Resources