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
- // MyView.h
- #import <UIKit/UIKit.h>
-
- @interface MyView : UIView {
- }
- @end
- // MyView.h
- #import <UIKit/UIKit.h>
-
- @interface MyView : UIView {
- }
- @end
In addition, you need to add an initWithFrame method in MyView. m.
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- // Initialization code
- }
- return self;
- }
That is to say, MyView. m is modified as follows:
Java code
- // 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
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!