HelloWorld Example in Xcode 4 – iPhone OS 4.3
来源:互联网 发布:国产男装品牌 知乎 编辑:程序博客网 时间:2024/05/17 21:59
This is the “Hello World” example. I am going to execute the Hello World example in a new version of Xcode. So many things are new in this Xcode 4.
Xcode 4 is the complete toolset for building Mac OS X and iOS applications, the tools have been redesigned to be faster, easier to use, and more helpful than ever before. The Xcode IDE understands your project’s every detail, identifies mistakes in both syntax and logic, and will even fix your code for you. Quite simply, Xcode 4 will help you write better code.
So let see how it will be work.
Step 1: Open a Xcode, select Create a new Xcode project (See fig 1) and click open button.
Now select ViewBase application and click next (See figure 2)
Next page you need to define Product name and Identifier name, the identifier is the name of your application. It’s the same name used when you register your application at Apple’s website and release it to the AppStore. The Product name “HelloWorld Xcode4” and the Identifier name “com.mycompany.APPLICATIONNAME” (See figure 3). Select the Device Family into iPhone. Now select next and save the application in your disk.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory (See the figure 4).
Step 3: Expand classes and notice Interface Builder created the HelloWorld_Xcode4ViewController class for you and generated a separate nib, HelloWorld_Xcode4ViewController.xib, for the “HelloWorld_Xcode4”.
Step 4: Select the HelloWorld_Xcode4ViewController.h file from the Project Navigator. We have added UILabel for display the text and added IBAction buttonPressed; in the file, so make the following changes in the file.
@interface HelloWorld_Xcode4ViewController : UIViewController {
IBOutlet UILabel *label;
}
@property (nonatomic, retain) IBOutlet UILabel *label;
-(IBAction)buttonPressed;
@end
Step 5: Double click the HelloWorld_Xcode4ViewController.xib file from Project Navigator. Now the .xib window will look like (figure 5).
a) Now drag the label and RoundRect button from the object (See figure 6).
b) Select Label from the Window and change the label Text name from the Attribute Inspector (See figure 7). Give the Text name “Hello World!!!”.
c) Next select the RoundRect Button from the window and select Attribute Inspector (See figure 8). Give the Title “Click Me”.
d) Now connect File’s Owner icon to the “Hello World!!!” label and select label (See figure 9).
e) Select “Click Me” button and bring up Connection Inspector (See figure 10) and connect Touch up Inside to the File’s Owner icon and select buttonPressed: method.
f) Select File’s Owner icon to the View window and select view (See figure 11).
Now save it and open the HelloWorld_Xcode4ViewController.m file from the Project Navigator.
Step 6: In the HelloWorld_Xcode4ViewController.m file make the following changes.
@implementation HelloWorld_Xcode4ViewController
@synthesize label;
-(IBAction)buttonPressed{
if ([label.text isEqualToString:@"Hello World!!!"])
label.text = @"Hello iPhone!!!";
else
label.text = @"Hello World!!!";
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Step 7: Now Compile and Run the application and see the Output in the Simulator.
- HelloWorld Example in Xcode 4 – iPhone OS 4.3
- [iphone开发]UISlider tutorial - example how to use slider in iPhone SDK / XCode
- An Example SQLite based iOS 4 iPhone Application (Xcode 4)
- iPhone/iPad Unit Test in xcode 4.3
- iPhone – UIActionSheet Example
- Spring 4 MVC HelloWorld Tutorial – Full XML Example
- Using openCV for Mac OS in XCode
- WIN7下虚拟机里安装MAC OS X 10.9.4里XCODE连接iPhone真机连不上
- first appkit in iphone and mac os
- Example Code of Using XML Parser in Symbian OS
- xcode 4 适配 iphone 3
- gcc in XCode 4.3
- Python in Xcode 4
- Python in Xcode 4
- programmatically-get-own-phone-number-in-iphone-os
- iphone develop uiscrollview example
- iphone 简单的 example -----
- XCode编译Iphone出现的问题:code signing is required for product type 'Application' in SDK 'iOS 4.3'
- openstack keystone 部署遇到的各种问题
- 每日一题(1)——滑雪问题(动态规划)
- 按键驱动
- word“域”的使用方法(转)
- Smarty中常用的变量调节器
- HelloWorld Example in Xcode 4 – iPhone OS 4.3
- 打印图形
- JavaScript+总结(一)
- PL/SQL块 基础
- WDM驱动改可手动加卸载的NT驱动
- smarty缓存
- 优化PHP性能实用技巧
- JavaScript+总结(二)
- C语言实现输入密码