UISplitViewControllerDisplayModePrimaryOverlay causes "Unbalanced calls to begin/end appearance transitions" - ios8

In iOS 8, setting the preferredDisplayMode on a UISplitViewController to PrimaryOverlay is generating the following warning:
"Unbalanced calls to begin/end appearance transitions for UINavigationController"
There is no problem if I set preferredDisplayMode to AllVisible or don't set it at all. Problem occurs for all iPads and iPhones in the simulator that I've tried. Problem occurs whether the app starts up in portrait or landscape.
Here's some very simple code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITableViewController *tableViewController = [[UITableViewController alloc] init];
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *masterNavController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
UINavigationController *detailNavController = [[UINavigationController alloc] initWithRootViewController:viewController];
UISplitViewController *svc = [[UISplitViewController alloc] init];
[svc addChildViewController:masterNavController];
[svc addChildViewController:detailNavController];
//svc.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
svc.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
self.window.rootViewController = svc;
[self.window makeKeyAndVisible];
return YES;
}

Wrap your display code in dispatch_async. Otherwise iOS seems to get confused with other animations running at the same time.
dispatch_async(dispatch_get_main_queue(), ^{
svc.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
});
or
dispatch_async(dispatch_get_main_queue()) {
svc.preferredDisplayMode = .PrimaryOverlay
}

Related

No root view controller error on Xcode 5

I get this error on Xcode 5:
Application windows are expected to have a root view controller at the end of application launch
My code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[Flurry startSession:#"HJ4X7X6PB3942VGHQWWZ"];
screenRect = [[UIScreen mainScreen] applicationFrame];
if (screenRect.size.height > 500)
{
isFive = YES;
NSLog(#"is iPhone 5");
}else{
isFive = NO;
}
[[SQLiteOperator sharedOperator] openDatabase];
[self setupLang];
[self handleTabBarLanguage];
[self handleAppUpdatePopUpLanguage];
_banner_view_controller = [[BannerViewController alloc] initWithNibName:#"BannerViewController" bundle:nil];
[_banner_view_controller send_request];
[_banner_view_controller didHidden];
[_navigation_controller.view addSubview:_banner_view_controller.view];
[CoreData sharedCoreData].banner_view_controller = _banner_view_controller;
// Create content and menu controllers
//
DEMONavigationController *navigationController = [[DEMONavigationController alloc] initWithRootViewController:[[DEMOHomeViewController alloc] init]];
DEMOMenuViewController *menuController = [[DEMOMenuViewController alloc] initWithStyle:UITableViewStylePlain];
// Create frosted view controller
//
REFrostedViewController *frostedViewController = [[REFrostedViewController alloc] initWithContentViewController:navigationController menuViewController:menuController];
frostedViewController.direction = REFrostedViewControllerDirectionLeft;
frostedViewController.liveBlurBackgroundStyle = REFrostedViewControllerLiveBackgroundStyleLight;
// Make it a root controller
//
self.window.rootViewController = frostedViewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
If you are using storyboard click on the project name in project navigator in Xcode. Then look for deployment info. Select Main Interface as your storyboard name. In app delegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// // Override point for customization after application launch.
// self.window.backgroundColor = [UIColor whiteColor];
// [self.window makeKeyAndVisible];
return YES;
}
And now try it.

Lock screen orientation for a single controller when there's a UITabBar in IOS 5 & 6

Following are the main poins I have.
I'm new to IOS development
I need to support IOS 5 and IOS 6 in my IOS app
I have a UITabBarController in AppDeligate file as follows.
UIViewController *viewController1 = [[[Grid1ViewController alloc] initWithNibName:#"Grid1ViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[VideoListViewController alloc] initWithNibName:#"VideoListViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[MusicViewController alloc] initWithNibName:#"MusicViewController" bundle:nil] autorelease];
UIViewController *viewController4 = [[[GalleryViewController alloc] initWithNibName:#"GalleryViewController" bundle:nil]autorelease];
UINavigationController *myNav1=[[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *myNav2=[[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *myNav3=[[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController *myNav4=[[UINavigationController alloc] initWithRootViewController:viewController4];
UIImage *navBackgroundImg = [UIImage imageNamed:#"aa.png"];
[myNav1.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
[myNav2.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
[myNav3.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
[myNav4.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:myNav1, myNav2, myNav3,myNav4,nil];
4.I want to lock the rotation of every controller which is directly connected to tabBarController( ex - Grid1ViewController). But I need to rotate the some controller which are used in the app. Please refer the following drawing. A,B,C,D and E are controllers.
I tried implementing following method in controllers and AppDeligate file. But didn't work. When rotation are allowed the whole app start to rotate.
(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation{
NSLog(#"5 rotation");
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
// For IOS 6
-(BOOL)shouldAutorotate {
NSLog(#"shouldAutorotate");
return YES;
}
(NSUInteger)supportedInterfaceOrientations {
NSLog(#"6 rotation");
return UIInterfaceOrientationMaskPortrait;
}
How can I achieve this? Please help. Thank you in advance.

How to Load View Controllers At the Beginning of the App?

I have a Tab View Controller as my root controller in an App which consists of 3 tabs let's call them View A, View B, View C.
I want to load these tabs as soon as my app starts, I think it can be done within didFinishLaunchingWithOptions function but I'm not exactly sure, does anyone know how to do it?
Thanks
For these kinds of purposes I used this approach:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
UITabBarController *tabBarController = [[UITabBarController alloc] init];
rootView = [[SGMenuViewController alloc] init];
UIViewController *tab1VC = [[UIViewController alloc] init];
UIViewController *tab2VC = [[UIViewController alloc] init];
UIViewController *tab3VC = [[UIViewController alloc] init];
UIViewController *tab4VC = [[UIViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootView];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:tab3VC];
NSArray* controllers = [NSArray arrayWithObjects:navController, tab2VC, secondNavController, tab4VC, nil];
tabBarController.viewControllers = controllers;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
You basically create a UITabBarController and you put all your view there. You create a UINavigationController if you need to push/pop views in the selected tab. In the example above only the 1st and the 3rd tab have UINavigationController and so I can use self.navigationController pushViewController: on them.

InputAccessoryView of a UITextField

I need to stick a toolBar with a UITextField inside to a keyboard.
What if I make the whole toolBar (which I think is the textField's super view) the inputAccessoryView of its textField?
I mean like this:
textField.inputAccessoryView = toolBar; // textField is inside the toolBar
I've been trying on this but I have not made it work yet.
Anyone can help?
Or is there another way to achieve what I want?
- (void)viewDidLoad
{
[self createAccessoryView];
[textField setDelegate:self];
[textField setKeyboardType:UIKeyboardTypeDefault];
[textField setInputAccessoryView:fieldAccessoryView];
}
- (void)createAccessoryView
{
CGRect frame = CGRectMake(0.0, self.view.bounds.size.height, self.view.bounds.size.width, 44.0);
fieldAccessoryView = [[UIToolbar alloc] initWithFrame:frame];
fieldAccessoryView.barStyle = UIBarStyleBlackOpaque;
fieldAccessoryView.tag = 200;
[fieldAccessoryView setBarStyle:UIBarStyleBlack];
UIBarButtonItem *spaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(done:)];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(#"Previous", #""), NSLocalizedString(#"Next", #""), nil]];
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl setMomentary:YES];
UIBarButtonItem *segmentButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[fieldAccessoryView setItems:[NSArray arrayWithObjects:segmentButton, spaceButton, doneButton, nil] animated:NO];
[segmentButton release];
[spaceButton release];
[doneButton release];
[segmentedControl release];
}
When are you setting the property? You may be setting it after the view has already loaded.
Try setting it in
- (void) viewDidLoad

Init a UInavigationbar

I am having trouble in making a tableview with navigation bar or controller on top.
I have this piece of code,
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *addNavCon = [[UINavigationController alloc]initWithNibName:#"Welcome" bundle:nil];
self.navigationItem.rightBarButtonItem = self.addButtonItem;
self.navigationItem.leftBarButtonItem = self.editButtonItem;
[self createEditableCopyOfDatabaseIfNeeded];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
NSString *documentDirectory = [self applicationDocumentsDirectory];
NSString *path = [documentDirectory stringByAppendingPathComponent:#"notebook.plist"];
NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
self.Notes = tmpArray;
[tmpArray release];
}
However, the navigation bar never show up, while the table is doing fine. May i know what's the problem with the code?
Many thanks
You have created an instance of UINavigationController but never added it to anything. You need to add it to the current hierarchy or it will not appear.
If you wish to add the navController to the entire app, then you should do this in the App Delegate by
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UIViewController *rootController = [[MyRootViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:rootController];
[rootController release];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
}

Resources