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
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
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
Last edited by a moderator: