IOS開發(fā)之解決iOS Hello World官方教程不能運行問題
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代碼
- // MyView.h
- #import <UIKit/UIKit.h>
- @interface MyView : UIView {
- }
- @end
- // MyView.h
- #import <UIKit/UIKit.h>
- @interface MyView : UIView {
- }
- @end
另外在MyView.m中需要添加一個initWithFrame方法。
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- // Initialization code
- }
- return self;
- }
也就是說MyView.m修改后如下:
Java代碼
- // MyView.m
- #import "MyView.h"
- @implementation MyView
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- // Initialization code
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect {
- NSString *hello = @"Hello, World!";
- CGPoint location = CGPointMake(10, 20);
- UIFont *font = [UIFont systemFontOfSize:24];
- [[UIColor whiteColor] set];
- [hello drawAtPoint:location withFont:font];
- }
- - (void)dealloc {
- [super dealloc];
- }
- @end
- // MyView.m
- #import "MyView.h"
- @implementation MyView
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- // Initialization code
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect {
- NSString *hello = @"Hello, World!";
- CGPoint location = CGPointMake(10, 20);
- UIFont *font = [UIFont systemFontOfSize:24];
- [[UIColor whiteColor] set];
- [hello drawAtPoint:location withFont:font];
- }
- - (void)dealloc {
- [super dealloc];
- }
- @end
小結(jié):IOS開發(fā) 解決iOS hello world官方教程不能運行問題的內(nèi)容介紹完了,這些東西在前面的教程中都沒有提到,我發(fā)現(xiàn)很多hello world程序都是存在一些小bug。希望本文對你有所幫助!