DAY
大家一起来建立一个 iPhone app,给你的iPhone显示 现时 的ip地址。
首先运行以安装好的 xCode
选择: File->New Project.
从 "New Project" 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 我这里命名为 "iPaddress"
(1)
#import <UIKit/UIKit.h>
@interface iPaddressViewController : UIViewController {
}
@property(nonatomic,retain) UILabel *showIPlabel;
@end
(2)
#import "iPaddressViewController.h"
@implementation iPaddressViewController
@synthesize showIPlabel;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
}
-(NSString *)getAddress {
}
- (void)dealloc {
}
(3) UIView 界面设置
双击文件: "MYIPViewController.xib" ;
然后 "Interface Builder"
(4) 加入
选择: Tools ->
(5)从 Interface Builder 写入 UILabel 的 class file
SDK工具 Interface Builder
在主视窗口或文件窗口;点击 Label
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "showIPlabel"; 选上它。
选择: File -> Save then close Interface Builde
以上几步,已成功完成界面了,下面我们继续把程式添加我们的代码文件。
最后在 xCode 选择Build->Build and Go
下载今天程序文件: WhatIsMyIp.zip