自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

移動開發(fā) iOS
本文介紹的是解決iOS hello world官方教程不能運行問題,主要講解了解決方案,我們先來看內(nèi)容。

IOS開發(fā) 解決iOS hello world官方教程不能運行問題是本文要介紹的內(nèi)容,經(jīng)過兩天的折騰,終于將iOS開發(fā)環(huán)境搭建起來。公司用的是Mac mini server 進行開發(fā)不光要搭建軟件環(huán)境,還要搭建硬件環(huán)境十分復(fù)雜,而且公司的網(wǎng)速非常慢,下載xcode和系統(tǒng)更新尤其是個大問題。今天整整跑了4趟網(wǎng)吧才搞定。

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

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的時候遇到一個問題就是程序一閃而過,沒有報錯,編譯成功,對與新手來說往往不知所措。

對比官方提供的源碼發(fā)現(xiàn)。MyView.h 內(nèi)需要做更改,即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 

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

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-12-30 15:17:23

Adobe視頻PhoneGap

2011-06-08 14:39:06

Qt 教程

2011-12-05 15:44:45

Knockout

2009-09-16 17:15:19

OSGi Bundle

2023-01-06 08:18:44

2011-08-05 09:48:46

iPhone Interface

2011-03-21 09:45:52

Hello WorldObjective-C生命周期

2011-08-03 09:44:18

IOS開發(fā) UITextFiel UITableVie

2014-09-17 11:45:20

iOS編程App運作

2016-12-12 13:19:32

iOS開發(fā)顯示

2011-09-08 10:41:12

Node.js

2016-12-13 14:12:25

程序機制

2016-12-14 14:41:20

Hello World程序運行機制

2012-03-06 10:22:00

程序

2014-07-23 13:17:53

iOSUITextField

2014-07-21 14:49:35

iOSUILabel

2010-03-15 15:18:23

Python運行

2012-08-27 09:10:05

JVMJava

2022-04-27 10:51:00

PythonMLCubePodman

2014-12-19 10:07:10

C
點贊
收藏

51CTO技術(shù)棧公眾號