DetailsIPhone DevelopmentThis document is intended for beginners.Iphone DevelopmentBasic tutorial, mainly to explainIphone DevelopmentAnd some simple implementations. Let's take a look at the details. First, we recommend an illustration of the iPhone development getting started tutorial for your reference!
Ideas:
1) Interface Builder Creation Interface
2) Add Outlet and Event Response functions to the header file.
3) establish association between interfaces and codes
4) Add the actual code (initialization, button response, etc)
Effect: Click to enlarge the second image)
Code:
Java code
-
- //
- // QuizAppDelegate. h
- // Quiz
- //
- // Created by bruce. lin on 6/21/11.
- // Copy 2011 _ MyCompanyName _. All rights reserved.
- //
- # Import <UIKit/UIKit. h>
- @ Interface QuizAppDelegate: NSObject <UIApplicationDelegate> {
- Int currentQuestionIndex;
- NSMutableArray * questions;
- NSMutableArray * answers;
- IBOutlet UILabel * questionField;
- IBOutlet UILabel * answerField;
- UIWindow * window;
- }
- @ Property (nonatomic, retain) IBOutlet UIWindow * window;
- -(IBAction) showQuestion :( id) sender;
- -(IBAction) showAnswer :( id) sender;
- @ End
- //
- // QuizAppDelegate. m
- // Quiz
- //
- // Created by bruce. lin on 6/21/11.
- // Copy 2011 _ MyCompanyName _. All rights reserved.
- //
- # Import "QuizAppDelegate. h"
- @ Implementation QuizAppDelegate
- @ Synthesize window = _ window;
- -(Id) init
- {
- [Super init];
- Questions = [[NSMutableArray alloc] init];
- Answers = [[NSMutableArray alloc] init];
- [Questions addObject: @ "How many meters is the iPhone? "];
- [Answers addObject: @ ""];
- [Questions addObject: @ "do not collect roadside wildflowers"];
- [Answers addObject: @ "a red apricot wall"];
- CurrentQuestionIndex = 0;
- Return self;
- }
- -(IBAction) showQuestion :( id) sender
- {
- CurrentQuestionIndex ++;
- If (currentQuestionIndex> = [questions count])
- {
- CurrentQuestionIndex = 0;
- }
- [QuestionField setText: [questions objectAtIndex: currentQuestionIndex];
- NSLog (@ "Current question is: % @", [questions objectAtIndex: currentQuestionIndex]);
- [AnswerField setText :@"? "];
- }
- -(IBAction) showAnswer :( id) sender
- {
- [AnswerField setText: [answers objectAtIndex: currentQuestionIndex];
- }
- -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( 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 shocould 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 records 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 previusly 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
Summary: DetailsIPhone DevelopmentThis document describes the content required for beginners.Iphone DevelopmentI hope this article will be helpful if I have learned something!