n00b struggling with black screen in iPhone simulator

Discussion in 'iOS Programming' started by steezy1337, Aug 1, 2011.

  1. steezy1337, Aug 1, 2011
    Last edited by a moderator: Aug 1, 2011

    macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #1
    Hi there, i've finally decided to jump into the world of iOS programming but i've hit a hurdle already :(

    i've been following the iPhone Programming book by the Big Nerd Ranch, copying the code in the first chapter character for character which has gone fine pretty much. i went to build and compile the code which returned no errors but when it's loaded up in the iPhone simulator all i get is a black screen when i click on the app. i've gone back over the code and can't see anything that stands out to me as wrong but it still isn't working. there was quite alot of code already included in the .h file that i left alone as i'm not sure if that has anything to do with it, i've bolded the text that i've added to what was already there

    Code:
    #import "QuizAppDelegate.h"
    
    @implementation QuizAppDelegate
    
    @synthesize window = _window;
    
    [B]- (id)init
    {
        //Call the init method implemented by the superclass
        [super init];
        
        //Create two arrays and make the pointers point to them
        questions =[[NSMutableArray alloc]init];
        answers = [[NSMutableArray alloc]init];
        
        //Add questions and answers to the arrays
        [questions addObject:@"What is 7 + 7?"];
        [answers addObject:@"14"];
        
        [questions addObject:@"What is the capital of England?"];
        [answers addObject:@"London"];
        
        [questions addObject:@"what is wine made from?"];
        [answers addObject:@"grapes"];
        
        // Return the address of the new object
        return self;
    }
    
    - (IBAction)showQuestion:(id)sender
    {
        //Step the the next question
        currentQuestionIndex++;
        
        //Am i past the last question?
        if(currentQuestionIndex == [questions count]){
    
            //Go back to the first question
            currentQuestionIndex = 0;
        }
        
        //Get the string at that index in the questions array
        NSString*question =[questions objectAtIndex:currentQuestionIndex];
        
        //Log the string to the console
        NSLog(@"dispaying question: %@",question);
        
        //Display the string in the question field
        [questionField setText:question];
        
        //Clear the answer field
        [answerField setText:@"???"];
    }[/B]
    
    -(IBAction)showAnswer:(id)sender
    {
        //What is the answer to the current question?
        NSString*answer = [answers objectAtIndex:currentQuestionIndex];
        
        //Display it in the answer field
        [answerField setText:answer];
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application
    {
        /*
         Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
         Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
         */
    }
    
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        /*
         Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
         If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
         */
    }
    
    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        /*
         Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
         */
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        /*
         Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
         */
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application
    {
        /*
         Called when the application is about to terminate.
         Save data if appropriate.
         See also applicationDidEnterBackground:.
         */
    }
    
    - (void)dealloc
    {
        [_window release];
        [super dealloc];
    }
    
    @end
    does anyone know how to fix this, or is it a different place where the problem is occurring? i'm sorry i'm really clueless to this :(
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    I think it should be appropriate learning how to know how the Flow of iOS works. You are putting all your code in the appdelegate, rather then in View Controllers.. that's not good.
    Because "the lotsa code in the .h" file, probably consists of a UINavigationController, or a view that it pushes itself on.
    Because now, it's just showing the mainwindow.xib, but not loading anything if i'm not mistaking.
    Imo, without trying to be rude, go learn the basics/iOS Flow etc. before you try to start something.
     
  3. thread starter macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #3
    thanks for the quick reply. one thing i did notice is that Xcode looks quite different in Lion than it does in the version that the pictures from the book are from, i'm presuming that things might have changed since then which could have something to do with it. is there somewhere i could learn these basics you speak of?
     
  4. macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #4
    Did you do all of the work in the .xib file? Drag on the buttons, drag on the labels, make the connections. All of this is described in figures 1.5, 1.6 and 1.10 - 1.13. If you are working with .xib files, writing the code is only half of the work. The other half is building the visual representation of your app in the .xib file(s).

    On a different note, it would probably be much better to learn C/Objective-C before learning iPhone programming. I know when I tried jumping straight into iPhone programming, with zero previous programming experience, before learning C/Objective-C I was totally lost.

    EDIT: I also have this book, so let me know if you are lost and I'll try to help you.
     
  5. thread starter macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #5
    yeah i've just gone back through and double checked everything is how it looks in the book. i think i'm getting a little thrown off with things looking different in the book to how they do in my version of Xcode. after a little looking most people suggest learning C first and taking it from there so i've found a mac focused guide that i'm gonna work through and take it from there. hopefully once they guides are updated for this new look Xcode i'll be a little more experienced!
     
  6. macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #6
    Let me work through the chapter really quick and I'll see if it works and if anything changes. I'll get back to you.
     
  7. macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #7
    Ok. So I worked through the chapter and the app works fine. I'm guessing you didn't do the work in the .xib file. My advice is to start the app from scratch (delete the first app you created) and build it after you add the buttons and labels in the .xib file. It should show the labels and buttons on the simulator, but nothing will work yet. At least you will know your .xib file is working. Then do the coding. If it still doesn't work, let me know.
     
  8. thread starter macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #8
    ok cheers for the help, i'll let you know how it goes
     
  9. steezy1337, Aug 1, 2011
    Last edited: Aug 1, 2011

    thread starter macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #9
    i've just re done all the code and been given a build fail error on the section where i've input the (IBAction)showQuestion:(id)sender code (on page 18/19). the errors are on both of the bolded question on this piece of code

    when i click on the error button it's saying that it's not declared, so i'm thinking this is possible a typo in the book.
    the only thing i've done differently this time i think is i've put all of this additional code at the bottom of all the code that was already there, could this be affecting it?

    EDIT: i tried changing the problem question to questions and it's built successfully and now loads up on the iPhone simulator! when i press on the show question button it goes blue but that seems like all that happens, and i'm pretty sure something should be happening?
     
  10. macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #10
    Do you see the labels and buttons when you run the app in the simulator? If you do, then it seems you still need to make the connections in Interface Builder. Look at Figures 1.9 - 1.13.
     
  11. macrumors newbie

    Joined:
    Aug 21, 2011
    #11
    Same problem..

    :mad:Yup, I'm having the same problem as steezy1337, no error is found but the simulator just shows a blank, grey screen. And yeeees, I have checked the connections.:mad:
     

Share This Page