How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?

The short answer is that you’re using UINavigationController, and that won’t work like you want it to. From Apple’s docs: Why won’t my UIViewController rotate with the device? All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set. To make sure that all your child view controllers rotate … Read more

Can’t cast value of type UIViewController to PatternDetailViewController

The problem, as you have said, is in these lines: if segue.identifier == “patternDetailSegue” { var detailViewController = segue.destinationViewController as! PatternDetailViewController // Could not cast value of type ‘UIViewController’ to ‘Patternz.PatternDetailViewController’ The error message tells you that the destinationViewController of this segue is not, in fact, a PatternDetailViewController. You may think it is, but it … Read more

difference between presentViewController and UINavigationController?

presentViewController offers a mechanism to display a so-called modal view controller; i.e., a view controller that will take full control of your UI by being superimposed on top of a presenting controller. UINavigationController offers a much more flexible mechanism where you can push a new controller, and later pop it, so to go back to … Read more

How to loop through view outlets in a UIViewController with Swift?

This is what Outlet Collections are for. Drag all your textfields in the same Outlet Collection in InterfaceBuilder and create an @IBOutlet to that collection in your class file: To create the outlet collection in InterfaceBuilder, ctrl-drag from the first UITextField to your class file in the assistant editor. Then choose Outlet Collection: ctrl-drag the … Read more

Shared iAd banner for UITabBarController based app using XCode 4 with storyboard

It’s fairly simple actually. Just create a new banner view controller for each tab that will be the parent view controller for each tab in your storyboard. Then drag in a Container View object into each banner view controller and embed your child view controllers in each banner view controller. Finally in BannerViewController.m replace the … Read more

Present a modal view controller with transparent background

Suppose, we’re in FirstViewController //Obj-C – (void) presentSecondVC { SecondViewController *vc = [[SecondViewController alloc] init]; [self addChildViewController:vc]; [self didMoveToParentViewController:vc]; } //Swift func presentSecondVC() { let vc = SecondViewController.init() self.addChildViewController(vc) self.didMove(toParentViewController: vc) } Some of you may need to write above method like this, //Obj-C – (void) presentSecondVC { SecondViewController *vc = [[SecondViewController alloc] init]; vc.view.frame … Read more

Application windows are expected to have a root view controller at the end of application launch warning

It’s odd to be setting your window’s rootViewController in application:didFinishLaunchingWithOptions: if you have a MainWindow.xib. Usually a project follows one of three templates: Some projects have a MainWindow.xib. The target’s “Main Interface” is set to “MainWindow” in the target’s Summary tab (or in its Info.plist). This xib’s File’s Owner is UIApplication. The xib contains an … Read more

Passing variables between view controllers

After performSegueWithIdentifier:sender: your view controler will call – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender assuming your new view controller has some propertys to set: if ([[segue identifier] isEqualToString:@”NextView”]) { MyViewController *myVC = [segue destinationViewController]; myVC.propertyToSet = // set your properties here }