Unbalanced calls to begin/end appearance transitions for <GKModalRootViewController: 0xb7e450> - iphone

I give up on that point, I just can't figure out what is wrong and where...
Here is the problem: in my iPhone application using Cocos2d, I configured autorotation through a viewController; however, since, when Game center opens its view as the user taps on "Create new account" during the authentication, this view does not receive any touch, but the touch go to the game's view (which is hidden under the Game center view).
I have tried everything I thought about, but since I did not find any callback about this Game Center View, it is hard to find a way to correct this...
Here is the initialization of the game's view:
// Init the UI View Controller
//
viewController = [[SQViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
EAGLView *view = [EAGLView viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGBA8 depthFormat:GL_DEPTH_COMPONENT24_OES];
[director setOpenGLView:view];
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[view removeFromSuperview];
[viewController setView:view];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
I have tried many other things, commented every single line in this code, tried some others (such as setHidden:NO, bringSubviewToFront...), but the only results I could get were:
- Game display ok, Game Center ok, but no autorotate
- Game displayed in portrait (the view controller only allow landscape modes), Game Center ok, no autorotate
- Game not displayed (black screen), Game Center ok
And no way to make it all work together... The only clue I have is the title of this topic, "Unbalanced calls to begin/end appearance transitions for ." But since I do not call the Game Center view myself, I don't know what to do with this...
Anyone, any idea?

I've had the same problem while displaying game center leaderboards in my cocos2d built App ever since moving up to iOS 5.0. I've seen references elsewhere to this being caused by a sub viewcontroller losing focus on the parent viewcontroller, but I've been unable to verify that or get this resolved in my app either.
Good news is that I've run this thru instruments - No Memory Leaks. Also executed the same action repetitively with no apparent failures or ill effects.
So while this message is an annoyance, it doesn't appear (at least for now) to adversely affect the App.

This Error occurs when you try to push a viewController before previous ViewController is finished . Means you are trying to push 2 ViewControllers at the same time.

Related

iOS subview size not correct when changing orientation

I got an app will do auto login for users. When logging in to the server, there will be a 50% transparent view with "logging in..." message showing and it blocked user from doing anything else(Please don't argue with me whether I should do that by HIG, we gotta let the user login in order to do anything). So what i did was create a xib LoadingMessageViewController in IB, and in the main view controller's - (void)viewDidLoad(), I initialize the view controller and do [self.view addSubview:LoadingMessageViewController.view];
It will work fine in portrait mode, but not in landscape. I saw tons of posts about this problem and nothing really worked for me.
I set autoresizingMask to true, set autosizing in IB, I also tried to use [[[window subviews] objectAtIndex:0] addSubview:LoadingMessageViewController.view] instead of [self.view addSubview:LoadingMessageViewController.view]. The problem with using [[window subviews] objectAtIndex:0] is it happen in -(void)ViewDidLoad, and at that point, the view has not really finished loading to the screen yet, and subviews at that point is nil, and call objectAtIndex will cause a pointer out of range exception.
Please point me to the right direction.
Thanks for reading my post.
This is how it looks like:

2 XIB and 1 viewcontroller but functions don't work in the ipad XIB

I believe that I did everything necessary to change my app for ipad (was for iphone at start). I can toggle the build status to either iphone (only), ipad (only) or iphone/ipad - and the app launches either in ipad or iphone simulator. I can do that forth and back at will.
I added the idiom to check for ipad and basically for one of my xib, instead of using the string of my xib to create the controller, I use the one for the ipad. So it is a new xib for ipad with all same graphical objects ( enlarged ;-) ) . I added the callbacks to function correctly with IB.
I can see everything fine and arrive on my new ipad view BUT when I click on one of my buttons... nothing happened like if my callbacks don't work. It is very surprising and actually I have no idea where to look as I compared most of the parameters between my iphone and ipad view and they are identical as far as I can see.
It must be something damn obvious so if one of you had the same issue and it was a very simple answer ... I guess that would be what I missed!
Thanks for your help in advance
Cheers,
geebee
EDIT1: Some code as requested
at start I have that to decide either way:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
examTFVC_NIB=#"ExamTFViewController-iPad";
}
else
{
examTFVC_NIB=#"ExamTFViewController";
}
Then to go to the right view:
ExamTFViewController *examTFViewController = [[ExamTFViewController alloc]
initWithNibName:globals.examTFVC_NIB bundle:nil];
But I have no problem loading the correct XIB. The issue is really the callback functions not being called...
Thanks for the help.
EDIT2:
I also realised that calling the extension of the xib xxx~ipad allows to avoid the example code above. And it works - but still no function can be called.
EDIT3:
IMPORTANT FINDING: if I move my buttons higher and on the left of the screen: they work! So it seems that the functions are called if the event are in the region of an iphone screen although I am on an ipad screen. I guess know it would be more obvious to find the issue! thanks for any help – geebee just now
ANSWER
iPad touch detected only in 320x480 region
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// to correct region size
CGRect rect = [[UIScreen mainScreen] bounds];
[window setFrame:rect];
// now, display your app
[window addSubview:rootController.view];
[window makeKeyAndVisible];
}
** OR OTHER SOLUTION **
Check the full screen at launch checkbox - only present in the ipad xib MainWindow
finally solved - with 2 methods - programmatically or via IB - in the edited section of the post.

Landscape/Portrait conflict - iOS

Just when i thought I had everything figured out .. i got this problem.
the scenario.
I got a simple tableView. and with a search bar in navigation item's titleView. The SearchBar is added to navItems titleView via a uibarbuttonitem in view controllers toolbar.
NOW, normally
After initiating the searchbar with [beginResponder] the keyboard shows up. And It sends out a notification "KeyboardDidShow" which is where i calculate the UIKeyboard's height and set the tableView's height accordingly (Shorten it).
ON Rotation - to and fro landscape/portrait, everything works fine.
-(void)didRotateInferfaceOrientation is called and everythings kool.
Heres the problem.
When the keyboard is active, it has a Google "search" button, this pushes to a new view - webviewcontroller.
the problem is, this
When, [PORTRAIT]ViewController [SearchBar with keyboard active] --> taps Search --> [Portrait]WebViewController --> Change Device Orientation to [Landscape] --> [Landscape]WebViewController changes to landscape ---> HERES THE PROBLEM, user taps back to uiViewController[Landscape]
the method -didRotatefromInterfaceOrientation isnt called. and somehow the tableView height is messed up. Though the view is rotating perfectly.
Is there something im missing here..
would appreciate any help. .thanks
When user taps back, -didRotatefromInterfaceOrientation will not be called. You need to check orientation in viewWillAppear (or call viewDidLoad, prior to returning from tap on back), and then call the proper layout for the chosen orientation.
In all of your (BOOL)shouldRotate... methods, you should be call a separate method to ensure your layout is correct for the device orientation.
I got a similar problem in one of my applications recently, not exactly our problem but don't bother, you should see what I'm heading for: I wanted to simply rotate an viewController displayed using presentModalViewController...Unfortunatly it didn't really worked put, especially on old iPhone with OS prior to iOS 4...So I needed to rotate programatically! Just get your screen size, use CGAffineTransform or something like that and change the sizes and then you should be done...
If your interested I could post a bunch of code, so let me know!
EDIT:
UIScreen *screen = [UIScreen mainScreen];
myController.view.bounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width - 20);
if(currentOrientation == UIDeviceOrientationLandscapeRight){
myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(-90)));
}else{
myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(90)));
}
myController.view.center = window.center;
[[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation];
[self.window addSubview:self.tabBarController.view];
[self.window bringSubviewToFront:self.tabBarController.view];
[self.window addSubview:myController.view];
[self.window bringSubviewToFront:myController.view];
[self.tabBarController.view removeFromSuperview];`
This also includes removing a TabBar when rotating to landscape to get some more space...enjoy :)
You could call didRotateFromInterfaceOrientation manually on viewWillAppear and just pass an orientation yourself (i.e. [UIApplication sharedApplication].statusBarOrientation).

iphone opengl backing becomes w=0 h=0 after MFMessageComposeViewController

I have an opengl game for iPhone/iPad (universal). I added the ability to send an SMS message using MFMessageComposeViewController. Testing in a real iPhone. The SMS composer sheet animates up over my view, I can send the message or not, didFinishWithResult gets called, and when I [self dismissModalViewControllerAnimated:YES] it goes away and my glview is asked to layoutSubviews. At that point the backing width and height are now zero, and my frame buffer status check fails. The self.layer.frame.size.width is still 320x460.
- (void)layoutSubviews
{
NSLog(#"layoutSubviews");
[EAGLContext setCurrentContext:context];
[self destroyFramebuffer];
[self createFramebuffer];
[self drawView];
}
I do have a UIViewController for my glView which is where I handle orientation changes for the iPad and where I also put the MFMessage stuff. (Technically I guess since it's universal there are two different viewControllers, two app Delegates and two nibs - but I'm working in the iPhone set here because the iPad doesn't sms). On the iPad layoutSubviews gets called when the orientation changes, we destroy and re-create the framebuffers at the new size and everything is fine. But here when coming back from sending the SMS it fails on the re-creating. I can post the code if necessary but its the standard creating framebuffer code.
Another important point is that I'm using a notification to tell the method inside of the viewcontroller to start the sms stuff. I tried just having those methods in my glview and making it the MFMessageComposeViewControllerDelegate but then I was getting errors because glview is a UIView and not a UIViewController.
Any ideas?
Not sure if it's a bug or what the deal is but I had to create another view, make self.view = anotherView, retain my glview and removeFromSuperview before presenting the modal. And then wait to bring my glview back until everything was animated back into place.
If anyone wants more info please let me know.
Edit with actual answer:
It is a bug and as I suspected it has to do with the status bar. My app has no status bar. But when I
[self presentModalViewController:controller animated:YES];
the SMS message composer view does show the iphone status bar. When it is dismissed and my app showed through underneath my framebuffer was getting borked. I had figured out a weird work around of switching views to protect my glview framebuffer - but then figured out to add a statusBarHidden before the dismiss and all is well now. Here's the dismiss code:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
// Notifies users about errors associated with the interface
switch (result)
{ ... }
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self dismissModalViewControllerAnimated:YES];
}

Only first UIView added view addSubview shows correct orientation

I've got three ViewControllers set up to handle three views. The problem that I'm having is that in the simulator the orientation is LandscapeRight (which is what I want), and the first view shows up correctly in that landscape view, but when I move onto the second and third views, they show up rotated 90 degrees counter-clockwise with the upper-left corner of the view in the lower left corner of the phone's screen. I've been trying to debug this for a few days and the closest that I've gotten to a clue is tracing it the following way:
The following is in my app delegate's applicationDidFinishLaunching:
NSLog(#"1");
[window addSubview:welcomeController.view];
NSLog(#"2");
[window addSubview:goalController.view];
NSLog(#"3");
[window addSubview:planningController.view];
NSLog(#"4");
[window bringSubviewToFront:welcomeController.view];
NSLog(#"5");
Each of my ViewControllers implement something similar to the following (the only change being the controller's name switched out in the string passed to NSLog):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
NSLog(#"called for WelcomeController");
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
With that, I get the following output on the Console:
a
called for WelcomeController
called for WelcomeController
called for WelcomeController
called for WelcomeController
2
called for GoalController
3
called for PlanningController
4
5
I find it interesting that shouldAutorotateToInterfaceOrientation is called 4 times for the first view that's added, while the other two only get called once. I expect that this is probably because it's got to do some setup at first (and I believe that the simulator starts off in portrait mode, so it's might be calling it while doing the rotation), but I find the correlation a bit suspicious.
I've switched the order around so that the addSubview is called for the goalController first and the welcomeController second. In this case, it's the goalController which displays in the correct landscape orientation (it's normally the welcome controller). This would seem to eliminate my XIB files and the ViewControllers themselves. I'm not sure why the first view where addSubview is called is special. I also tried using insertSubview at index 0 with the same results.
Ran into the same problem, and apparently adding subviews to a UIWindow doesn't work the way I expected it to. I managed to solve the problem after adding a "dummy" UIViewController that is the ONLY subview in the UIWindow. After adding that one, it works perfectly to add multiple subviews to the dummy-controller, all with the correct orientation.
So the only code in the "dummy" controller class is the "shouldAutorotateToInterfaceOrientation" function. This should also match the same function in all the other subviews.
Hope it helps.
I had a similar issue. Not sure why either. But the workaround was to call this on every view after the first one:
[planningController.view setFrame:CGRectMake(0, 0, 480, 300)];
and before -addView. I'm curious if this helps you out. If I am not the only one with this problem and this workaround, then maybe there's a reason.
This is far far far from ideal. But you can hack the second views transform so it is rotated correctly. This works for me because my app is only ever in landscape mode. It may not be ideal if you want to change orientation.
[window addSubview:firstController.view];
[window addSubview:secondController.view];
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI/2.0);
[backgroundViewController.view setTransform:rotate];
CGRect contentRect = CGRectMake(0, 0, 1024, 768);
backgroundViewController.view.bounds = contentRect;
[backgroundViewController.view setCenter:CGPointMake(768/2, 1024/2)];
I think I have a solution for this that appears to work. Add a view, and then immediate remove it, repeat for each view, then add all three. Like this:
[window addSubview:welcomeController.view];
[welcomeController.view removeFromSuperview];
[window addSubview:goalController.view];
[goalController.view removeFromSuperview];
[window addSubview:planningController.view];
[planningController.view removeFromSuperview];
[window addSubview:welcomeController.view];
[window addSubview:goalController.view];
[window addSubview:planningController.view];
It seems to work, at least in the simulator.