Beginner's Guide to iPhone Development

Source: Internet
Author: User

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

 
 
  1.  
  2. //
  3. // QuizAppDelegate. h
  4. // Quiz
  5. //
  6. // Created by bruce. lin on 6/21/11.
  7. // Copy 2011 _ MyCompanyName _. All rights reserved.
  8. //
  9. # Import <UIKit/UIKit. h>
  10. @ Interface QuizAppDelegate: NSObject <UIApplicationDelegate> {
  11. Int currentQuestionIndex;
  12. NSMutableArray * questions;
  13. NSMutableArray * answers;
  14. IBOutlet UILabel * questionField;
  15. IBOutlet UILabel * answerField;
  16. UIWindow * window;
  17. }
  18. @ Property (nonatomic, retain) IBOutlet UIWindow * window;
  19. -(IBAction) showQuestion :( id) sender;
  20. -(IBAction) showAnswer :( id) sender;
  21. @ End
  22. //
  23. // QuizAppDelegate. m
  24. // Quiz
  25. //
  26. // Created by bruce. lin on 6/21/11.
  27. // Copy 2011 _ MyCompanyName _. All rights reserved.
  28. //
  29. # Import "QuizAppDelegate. h"
  30. @ Implementation QuizAppDelegate
  31. @ Synthesize window = _ window;
  32. -(Id) init
  33. {
  34. [Super init];
  35. Questions = [[NSMutableArray alloc] init];
  36. Answers = [[NSMutableArray alloc] init];
  37. [Questions addObject: @ "How many meters is the iPhone? "];
  38. [Answers addObject: @ ""];
  39. [Questions addObject: @ "do not collect roadside wildflowers"];
  40. [Answers addObject: @ "a red apricot wall"];
  41. CurrentQuestionIndex = 0;
  42. Return self;
  43. }
  44. -(IBAction) showQuestion :( id) sender
  45. {
  46. CurrentQuestionIndex ++;
  47. If (currentQuestionIndex> = [questions count])
  48. {
  49. CurrentQuestionIndex = 0;
  50. }
  51. [QuestionField setText: [questions objectAtIndex: currentQuestionIndex];
  52. NSLog (@ "Current question is: % @", [questions objectAtIndex: currentQuestionIndex]);
  53. [AnswerField setText :@"? "];
  54. }
  55. -(IBAction) showAnswer :( id) sender
  56. {
  57. [AnswerField setText: [answers objectAtIndex: currentQuestionIndex];
  58. }
  59. -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
  60. {
  61. // Override point for customization after application launch.
  62. [Self. window makeKeyAndVisible];
  63. Return YES;
  64. }
  65. -(Void) applicationWillResignActive :( UIApplication *) application
  66. {
  67. /*
  68. Sent when the application is about to move from active to inactive state.
  69. This can occur for certain types of temporary interruptions
  70. (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.
  71. Use this method to pause ongoing tasks, disable timers,
  72. And throttle down OpenGL ES frame rates. Games shocould use this method to pause the game.
  73. */
  74. }
  75. -(Void) applicationDidEnterBackground :( UIApplication *) application
  76. {
  77. /*
  78. Use this method to release shared resources, save user data, invalidate timers,
  79. And store enough application state information to restore your application to its current state in case it is terminated later.
  80. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  81. */
  82. }
  83. -(Void) applicationWillEnterForeground :( UIApplication *) application
  84. {
  85. /*
  86. Called as part of the transition from the background to the inactive state;
  87. Here you can undo records of the changes made on entering the background.
  88. */
  89. }
  90. -(Void) applicationDidBecomeActive :( UIApplication *) application
  91. {
  92. /*
  93. Restart any tasks that were paused (or not yet started) while the application was inactive.
  94. If the application was previusly in the background, optionally refresh the user interface.
  95. */
  96. }
  97. -(Void) applicationWillTerminate :( UIApplication *) application
  98. {
  99. /*
  100. Called when the application is about to terminate.
  101. Save data if appropriate.
  102. See also applicationDidEnterBackground :.
  103. */
  104. }
  105. -(Void) dealloc
  106. {
  107. [_ Window release];
  108. [Super dealloc];
  109. }
  110. @ End

Summary: DetailsIPhone DevelopmentThis document describes the content required for beginners.Iphone DevelopmentI hope this article will be helpful if I have learned something!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.