IOS開發之解決iOS Hello World官方教程不能運行問題

來源:互聯網
上載者:User

IOS開發 解決iOS hello world官方教程不能運行問題是本文要介紹的內容,經過兩天的折騰,終於將iOS開發環境搭建起來。公司用的是Mac mini server 進行開發不光要搭建軟體環境,還要搭建硬體環境十分複雜,而且公司的網速非常慢,下載xcode和系統更新尤其是個大問題。今天整整跑了4趟網吧才搞定。

言歸正傳,在安裝官方的例子

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

寫hello world的時候遇到一個問題就是程式一閃而過,沒有報錯,編譯成功,對與新手來說往往不知所措。

對比官方提供的源碼發現。MyView.h 內需要做更改,即MyView.h需要繼承UIView.

更改後的MyView.h代碼如下:

Java代碼 

 
  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 

另外在MyView.m中需要添加一個initWithFrame方法。

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

也就是說MyView.m修改後如下:

Java代碼 

 
  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 

小結:IOS開發 解決iOS hello world官方教程不能運行問題的內容介紹完了,這些東西在前面的教程中都沒有提到,我發現很多hello world程式都是存在一些小bug。希望本文對你有所協助!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.