IOS开发之解决iOS Hello World官方教程不能运行问题

移动开发 iOS
本文介绍的是解决iOS hello world官方教程不能运行问题,主要讲解了解决方案,我们先来看内容。

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。希望本文对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-12-30 15:17:23

Adobe视频PhoneGap

2011-06-08 14:39:06

Qt 教程

2011-12-05 15:44:45

Knockout

2011-03-21 09:45:52

Hello WorldObjective-C生命周期

2014-09-17 11:45:20

iOS编程App运作

2011-08-03 09:44:18

IOS开发 UITextFiel UITableVie

2023-01-06 08:18:44

2009-09-16 17:15:19

OSGi Bundle

2011-08-05 09:48:46

iPhone Interface

2016-12-12 13:19:32

iOS开发显示

2014-07-23 13:17:53

iOSUITextField

2012-03-06 10:22:00

程序

2016-12-14 14:41:20

Hello World程序运行机制

2016-12-13 14:12:25

程序机制

2014-07-21 14:49:35

iOSUILabel

2011-09-08 10:41:12

Node.js

2011-07-08 14:58:16

iPhone Xcode iOS

2012-05-14 16:59:40

iOS

2013-07-23 07:24:57

iOS开发学习iOS开发问题集锦

2022-04-27 10:51:00

PythonMLCubePodman
点赞
收藏

51CTO技术栈公众号