IOS development solves the problem that the official iOS Hello World tutorial cannot run

Source: Internet
Author: User

IOS developmentSolutionIOSThe official hello world tutorial cannot run. The problem is described in this article. After two days of hard workIOS developmentBuild the environment. The company uses Mac mini server for development. Not only does it need to build a software environment, but it also needs to build a hardware environment very complex. Moreover, the company's network speed is very slow. Downloading xcode and system updates is especially a big problem. Today, I ran four full-site Internet cafes.

To put it bluntly, install the official example

Http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/100-iOS_Development_Quick_Start/development_quick_start.html#//apple_ref/doc/uid/TP40007959-CH3-SW1

When writing hello world, a problem occurs: The program experiences a flash, no error is reported, and the compilation is successful, which is often at a loss for new users.

Compared with the official source code. MyView. h needs to be changed, that is, MyView. h needs to inherit UIView.

The changed MyView. h code is as follows:

Java code

 
 
  1. // MyView.h     
  2. #import <UIKit/UIKit.h>     
  3.       
  4. @interface MyView : UIView {     
  5. }     
  6. @end    
  7. // MyView.h  
  8. #import <UIKit/UIKit.h> 
  9.    
  10. @interface MyView : UIView {  
  11. }  
  12. @end 

In addition, you need to add an initWithFrame method in MyView. m.

 
 
  1. - (id)initWithFrame:(CGRect)frame {   
  2.     if (self = [super initWithFrame:frame]) {   
  3.         // Initialization code   
  4.     }   
  5.     return self;   
  6. }  

That is to say, MyView. m is modified as follows:

Java code

 
 
  1. // MyView.m     
  2. #import "MyView.h"    
  3.       
  4. @implementation MyView     
  5.       
  6. - (id)initWithFrame:(CGRect)frame {     
  7.     if (self = [super initWithFrame:frame]) {     
  8.         // Initialization code     
  9.     }     
  10.     return self;     
  11. }     
  12.       
  13. - (void)drawRect:(CGRect)rect {     
  14.    NSString *hello   = @"Hello, World!";     
  15.    CGPoint  location = CGPointMake(10, 20);     
  16.    UIFont   *font    = [UIFont systemFontOfSize:24];     
  17.    [[UIColor whiteColor] set];     
  18.    [hello drawAtPoint:location withFont:font];     
  19. }     
  20.       
  21. - (void)dealloc {     
  22.     [super dealloc];     
  23. }     
  24.       
  25. @end    
  26.  
  27. // MyView.m  
  28. #import "MyView.h"  
  29.    
  30. @implementation MyView  
  31.    
  32. - (id)initWithFrame:(CGRect)frame {  
  33.     if (self = [super initWithFrame:frame]) {  
  34.         // Initialization code  
  35.     }  
  36.     return self;  
  37. }  
  38.    
  39. - (void)drawRect:(CGRect)rect {  
  40.    NSString *hello   = @"Hello, World!";  
  41.    CGPoint  location = CGPointMake(10, 20);  
  42.    UIFont   *font    = [UIFont systemFontOfSize:24];  
  43.    [[UIColor whiteColor] set];  
  44.    [hello drawAtPoint:location withFont:font];  
  45. }  
  46.    
  47. - (void)dealloc {  
  48.     [super dealloc];  
  49. }  
  50. @end 

Summary:IOS developmentSolutionIOSThe content of the "hello world" official tutorial cannot run the problem is described. These things are not mentioned in the previous tutorial. I found that many hello world programs have some minor bugs. I hope this article will help you!

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.