ViewController doesn't show until I quit and relaunch app - iphone

I have just made my app universal by combining separate iPhone and iPad projects. Everything seems to be working but there is one major bug.
When the iPad app launches it just displays a black screen (presumably the window) and status bar. When I press the home button I suddenly see the SplitViewController as it disappears. When I open the app up again the SplitViewController is displayed.
I can't figure out why the controller only displays after I close and reopen the app. Any ideas?
(I don't have any idea what is causing this so if you need code samples from specific places let me know).
Thanks.
Edit:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Appirater appLaunched:YES];
// Registers this class as the delegate of the audio session.
[[AVAudioSession sharedInstance] setDelegate: self];
// Allow the app sound to continue to play when the screen is locked.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
justOpened = YES;
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
{deleted}
} else {
[self.window addSubview:self.splitViewController.view];
[self.window makeKeyAndVisible];
CGRect rect = CGRectMake(-2, self.window.frame.size.height-29, self.window.frame.size.width+2, 29);
imgBar = [[UIImageView alloc] initWithFrame:rect];
imgBar.contentMode = UIViewContentModeScaleToFill;
imgBar.image = [UIImage imageNamed:#"wood_btm.png"];
imgBar.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
self.splitViewController.showsMasterInPortrait = YES;
self.splitViewController.title = #"Exams";
self.splitViewController.splitPosition=280;
}
return YES;
}
Update:
By messing around with the window's background color I discovered that for some reason it was at the top of the view hierarchy. I then made the window's background color clear and I could see the SplitViewController. Strangely I can also interact with it. So essentially I have solved the problem by making the window clear. This is obviously not the ideal solution though so if anyone can think of a cause let me know.

[self.window addSubview:self.splitViewController.view];
[self.window makeKeyAndVisible];
return YES;
should be at the end of -applicationDidFinishLaunching:WithOptions: method.

By messing around with the window's background color I discovered that for some reason it was at the top of the view hierarchy. I then made the window's background color clear and I could see the SplitViewController. Strangely I can also interact with it. So essentially I have solved the problem by making the window clear.

Related

Build succeeds but black screen

The build process is fine but then i get a black screen. I tried putting a breakpoint in the app delegate but it doesn't seem to run.
What could it be?
This is my didFinishLaunchingWithOptions method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Init Airship launch options
NSMutableDictionary *takeOffOptions = [[[NSMutableDictionary alloc] init] autorelease];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
// Create Airship singleton that's used to talk to Urban Airship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
// Register for notifications
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
usersData = [PlayersData sharedInstance];
//[usersData cleanUserDefauts]; // --- use to clean user defaults
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.loadingPageVC = [[LoadingPage alloc] initWithNibName:#"LoadingPage" bundle:nil];
self.window.rootViewController = self.loadingPageVC;
[self.window makeKeyAndVisible];
ConnectionManager *connectionManager = [ConnectionManager sharedInstance];
NSLog(#"Connection statement: %#",[connectionManager checkConnection]);
if ([[connectionManager checkConnection] isEqualToString:#"connected with wifi"] || [[connectionManager checkConnection] isEqualToString:#"connected with wwan"] ) {
[connectionManager getLocation];
}
return YES;
}
Sometimes(Very Rarely) XCode can behave different.If something is really weird i would do the following things.
Do a clean build
Remove your app in the Simulator and Build Again
Restart Simulator and Build Again
Close XCode and Reopen it
Worst case is to restart the System
No need to resart anything. Just follow a step given below & you will achieve what you want.
1. Go to /Users/<MAC_NAME>/Library/Application Support/iPhone Simulator/<SIMULATOR_VERSION>, delete all & run app
Enjoy Programming!
I think you may have changed your xib name from ViewController to LoadingPage.
If so, then you must have to delegate it from your .xib. From the top-right corner. Like,
I have just given my opinion that this may be your solution. If you have succeeded with another one, let me know.....:)
Ok! This is solved.
Apparently someone I work with changed one simple word and that messed everything up…
He made the appDelegate inherit from UIApplication instead from UIResponder.
Now it works.

Crash iPad Photo Picker

I am using the following function to activate either the device camera or the image picker depending on the result of a UIActionSheet. if fromCamera=YES then it works on both iPhone and iPad. if fromCamera=NO then it works on iPhone and the image picker appears. But it crashes on the iPad with the following error: UIStatusBarStyleBlackTranslucent is not available on this device. I already know that the iPad can't display the UIStatusBarStyleBlackTranslucent statusBar, but how do I avoid this crash?
-(void)addPhotoFromCamera:(BOOL)fromCamera{
if(fromCamera){
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:picker animated:YES];
}
If you set the picker to UIImagePickerControllerSourceTypePhotoLibrary on the iPad, then you must(!) present it in a popoverview, otherwise you get exceptions. I do it like this, to atleast control the size of the popover (the standard size is too small in my opinion):
-(void)openPhotoPicker
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.navigationBar.opaque = true;
//put the image picker in its own container controller, to control its size
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = rightPane.frame.size;
[containerController.view addSubview:imagePicker.view];
//then, put the container controller in the popover
popover = [[UIPopoverController alloc] initWithContentViewController:containerController];
//Actually, I would like to do the following, but iOS doesn't let me:
//[rightPane addSubview:imagePicker.view];
//So, put the popover over my rightPane. You might want to change the parameters to suit your needs.
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 10.0,0.0)
inView:rightPane
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
//There seems to be some nasty bug because of the added layer (the container controller), so you need to call this now and each time the view rotates (see below)
[imagePicker.view setFrame:containerController.view.frame];
}
I also have the following, to counter a rotation bug:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if(imagePicker!=nil && rightPane.frame.size.width>0)
[imagePicker.view setFrame:imagePicker.view.superview.frame];
}
It ain't perfect, but it is ok for my testing purposes at the moment. I consider writing my own Imagepicker, because I don't like being forced to use the popoverview... but well, that's a different story.
I suspect the UIImagePicker is inheriting the translucent status bar from your Info.plist file or from the currently displayed view controller.
What happens if you make the app not have a translucent status bar?
I was having a similar issue, take a look at my answer here:
https://stackoverflow.com/questions/7677058/uiimagepickercontroller-crash-in-ipad-ios5/7839969#7839969

Game Center windows don't scroll smoothly on OpenGL game

I have an shipped OpenGL game that I'm adding Game Center support to for a 1.1 rev. The game does not use a UIViewController and is coded as follows in the AppDelegate:
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:YES];
glView = [[EAGLView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window addSubview:glView];
[window makeKeyAndVisible];
[glView performSelectorOnMainThread:#selector(mainGameLoop) withObject:nil waitUntilDone:NO];
}
Everything works great, but when Game Center brings up a window (GKAchievementViewController for example), the window animates on screen fine, but when I touch to scroll it, it doesn't have any of the momentum or bounce-back like normal windows. When I scroll the window past the top and bottom and it doesn't return with bounce back.
The window is fully functional, registers touches, it just behaves ugly.
I assume this is because some information is just not being sent down the pipe correctly because I don't have a UIViewController? I tried creating a UIViewController that sits in-between the UIWindow and the OpenGL UIView, but I get the same behavior.
This is how I'm creating the GKAchievementViewController dialog:
-(void)displayAchievements
{
achievmentsViewController = [[UIViewController alloc] init];
[glView addSubview:achievmentsViewController.view];
GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[achievmentsViewController presentModalViewController:achievements animated:YES];
}
[achievements release];
}
I don't use any of the UIKit in the game, all buttons, etc are done with straight OpenGL. I am also not using cocos2d or any other framworks.
In my main loop I am doing this:
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.002, TRUE) == kCFRunLoopRunHandledSource);
Other than that, I am not making any regular calls into the OS.
Does anyone know what is going on? My game is ready to submit other than this problem and it's driving me crazy.
OK, I think I found the answer to this so I'm going to answer my own question in the hopes of saving others a lot of frustration.
The problem is CFRunLoopRunInMode. It doesn't play nice with UIKit. I switched to using CADisplayLink and all is well.
displayLink = [NSClassFromString(#"CADisplayLink") displayLinkWithTarget:self selector:#selector(mainLoopBody)];
[displayLink setFrameInterval:1];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
I've read that CADisplayLink is causing some games problems and there is a lot of debate about using it vs CFRunLoopRunInMode vs NSTimer. I'll use this for a while and see if it causes any problems, but windows scroll right again.
My one concern with CADisplayLink is if the frame rate starts to bog down. Under my old CFRunLoopRunInMode system, if the frames took longer the delta time reflected that. With CADisplayLink, I'm not sure if that is still the case.
Oh the fun of programming.

iPad app: keyboard for editing UITextField does not always show

I have a text field that is manually set to be the first responder. There are times when this works fine, and others when it fails.
My application is a game with two methods of play: flashcard and regular. The UITextField that is the source of trouble is hidden and not used in flashcard mode. Once flashcard has loaded once, the keyboard ceases to appear. If the player never switches to flashcard mode, the keyboard never fails. The following is the code to make the keyboard show:
nameBar.hidden = FALSE;
self.animalName.hidden = FALSE;
self.animalName.enabled = YES;
[self.animalName becomeFirstResponder];
This is the code that switches modes:
playViewController = nil;
[playViewController release];
playViewController = [[PlayViewController alloc] initWithNibName:#"PlayView" bundle:nil];
playViewController.delegate = self;
[(vsl_mmp_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] playButtonPlaySound];
playViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
playViewController.flashcardMode = TRUE;
[self presentModalViewController:playViewController animated:YES];
[(vsl_mmp_crittersAppDelegate*)[[UIApplication sharedApplication] delegate] playPlayMusic];
I'm really confused about why the UITextField ceases to work after I switch modes, especially since I completely release and re-allocate the play controller to do so.
Thanks for reading.
Where are you calling becomeFirstResponder from?
Calling it from viewDidLoad will give you the behavior you describe, and calling it from viewDidAppear: should show the keyboard each time the view appears.

FBlogin dialog box orientation problem

I'm facing a very silly problem and its really hard to resolve for me.
The fblogindialog box that i'm using in my application, appearing in portrait mode always.. But my whole application is in landscape mode.. the main thing is that the keyboard appears landscape and the web view in wich the login appears has the orientation which just suits the landscape mode (means the username and pwd txt boxes are that much wide so that if we rotate the device it would just fit into the landscape mode).
I tried every thing i looked for the status bar orientaition as well. its really frustrating. i'm using a button named post and on the click of this button i written the following code:
AppDelegate_iPhone *appDelegate =(AppDelegate_iPhone *)[[UIApplication sharedApplication]delegate];
if (appDelegate._session == nil)
{
appDelegate._session = [FBSession sessionForApplication:_APP_KEY secret:_SECRET_KEY delegate:self];
}
if(self.loginDialog == NULL || ![appDelegate._session resume])
{
self.loginDialog = [[[FBLoginDialog alloc] init] autorelease];
loginDialog.delegate = self;
[self.loginDialog show];
//self.loginDialog.frame = CGRectMake(0, 0, 480, 320);
[self.view addSubview:loginDialog];
}
here is the screen shot link-- http://i.stack.imgur.com/X4UHi.png
Please help me guys..
Thks very much .
finally i used new facebook sdk to solve this problem. and used the graph apis . A sample which explain all of this is --
https://github.com/reallylongaddress/iPhone-Facebook-Graph-API
and very helpful indeed.
Thanks