版权所有,欢迎转载,转载请注明 : SinFrancis http://mdev.cc

iphone NIB文件 -> android xml布局文件

iphone delegate class + controller class -> android Activity

main方法 -> android的中AndroidManifest.xml要启动的Activity

步骤:

1. 使用XCODE创建项目

2. 打开nib文件,将需要的组件拖放至view中

3. 在Controller类中声明组件变量 \ 事件接收方法,注意需要 IBOutlet关键字,

4. 使用InterfaceBuilder链接Controller类中的变量\事件接收方法 至 每个组件上

5. 实现事件接收方法

(不用InterfaceBuilder依然可以实现UI界面,使用纯Code编写.)

main:

////  main.m//  HelloUser////  Created by sin francis on 10-8-26.//  Copyright __MyCompanyName__ 2010. All rights reserved.//#import <UIKit/UIKit.h>int main(int argc, char *argv[]) {        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];    int retVal = UIApplicationMain(argc, argv, nil, nil);    [pool release];    return retVal;}

Delegate声明:

HelloUserAppDelegate.h

////  HelloUserAppDelegate.h//  HelloUser////  Created by sin francis on 10-8-26.//  Copyright __MyCompanyName__ 2010. All rights reserved.//#import <UIKit/UIKit.h>@class HelloUserViewController;@interface HelloUserAppDelegate : NSObject <UIApplicationDelegate> {    UIWindow *window;    HelloUserViewController *viewController;}@property (nonatomic, retain) IBOutlet UIWindow *window;@property (nonatomic, retain) IBOutlet HelloUserViewController *viewController;@end

Delegata的实现:

HelloUserAppDelegate.m

////  HelloUserAppDelegate.m//  HelloUser////  Created by sin francis on 10-8-26.//  Copyright __MyCompanyName__ 2010. All rights reserved.//#import "HelloUserAppDelegate.h"#import "HelloUserViewController.h"#import "MyNewsViewController.h"@implementation HelloUserAppDelegate@synthesize window;@synthesize viewController;- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {            // Override point for customization after app launch        [window addSubview:viewController.view];    [window makeKeyAndVisible];return YES;}- (void)dealloc {    [viewController release];    [window release];    [super dealloc];}@end

Controller的声明:

////  HelloUserViewController.h//  HelloUser////  Created by sin francis on 10-8-26.//  Copyright __MyCompanyName__ 2010. All rights reserved.//#import <UIKit/UIKit.h>@interface HelloUserViewController : UIViewController {//链接到HelloUserViewController.xib 界面中的display label组件IBOutlet UILabel *displayLable;//链接到HelloUserViewController.xib 界面中的name Field组件IBOutlet UITextField *nameField;//链接到HelloUserViewController.xib 界面中的Button组件IBOutlet UIButton *sayButton;//注意:以上的只是引用,并未真实的链接到组件上去,那么就需要我们使用Interface Builder进行链接//1. 使用Interface Builder打开HelloUserViewController.xib,打开HelloUserViewController.xib中View//2. 右键单击 或者CTRL+左键单击 "File's Owner",可以在弹出的Outlet一栏中看见  //displayLable nameField sayButton三个变量名称//3. 分别拖动变量右边的空心圈连接至View界面上的组件即可}//定义一个按钮事件接收器//如何链接此接收器到button上呢//1. 使用Interface Builder打开HelloUserViewController.xib,打开HelloUserViewController.xib中View//2. 右键单击 或者CTRL+左键单击 "File's Owner",在Received Actions一栏中可以看到sayHello的动作//3. 拖动sayHello右边的空心圈至View界面上的按钮即可//4. 实现你的sayHello方法吧-(IBAction) sayHello : (id) sender;@end

Contoller的实现:

////  HelloUserViewController.m//  HelloUser////  Created by sin francis on 10-8-26.//  Copyright __MyCompanyName__ 2010. All rights reserved.//#import "HelloUserViewController.h"@implementation HelloUserViewController/*// The designated initializer. Override to perform setup that is required before the view is loaded.- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {        // Custom initialization    }    return self;}*//*// Implement loadView to create a view hierarchy programmatically, without using a nib.- (void)loadView {}*//*// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad {    [super viewDidLoad];}*//*// Override to allow orientations other than the default portrait orientation.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    // Return YES for supported orientations    return (interfaceOrientation == UIInterfaceOrientationPortrait);}*///sayHello的实现方法-(void) sayHello:(id)sender{NSString *userName = nameField.text;NSString *helomessage = [[NSString alloc] initWithFormat:@"Hello,%@",userName];displayLable.text=helomessage;[helomessage release];nameField.text=NULL;}- (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 {// Release any retained subviews of the main view.// e.g. self.myOutlet = nil;}- (void)dealloc {    [super dealloc];}@end

实例代码下载:

更多相关文章

  1. 链接器解析多重定义的全局变量
  2. android mtk6592 禁止拖动主界面图标
  3. Android 自定义组件 方法篇
  4. Windows环境下Android Studio系列4—界面介绍
  5. Android Interface(UI) 界面控件简单介绍01
  6. Android四大组件的理解
  7. android Button组件的属性和方法
  8. Android入门学习笔记之人机用户界面
  9. 怎么去掉联系人、通话记录、拨号列表界面中的电话号码中间的空格

随机推荐

  1. 可折叠的列表ExpandableListView及其适配
  2. 覆盖Android开发各个领域的近百个源码项
  3. 刚开始安卓,记录一个刚做的图片缩放程序
  4. Android常用命令
  5. 〖Android〗dropbear一些操作命令备忘
  6. javaeye中的一些好的android博客
  7. 《宅男的android开发指南》(翻译)--2
  8. Android(安卓)近百个项目的源代码,覆盖And
  9. Android选项切换条SHSegmentControl
  10. Android(安卓)support和Androidx库不能共