《《Iphone总结》.doc
文本预览下载声明
1.创建第一个程序
1).创建项目 ,然后添加一个新的viewcontroller文件,这时会生成.h .m .xib文件 ,在项目 名称appdeletegate.h中添加
UINavigationController *mainNavigation;
2).在.m文件中application方法中添加
//别忘记 导入包
mainNavigation=[[UINavigationController alloc]init ];
mainNavigation=[[UINavigationController alloc]init ];
MainViewController*mainView=[[MainViewController alloc]init ];
mainView.title=@主页面;
//将viewcontroller添加到主导航器中
[mainNavigation pushViewController:mainView animated:NO];
//将mainNavigation作为程序的导航器
[self.window addSubview:mainNavigation.view];
//将mainview释放
[mainView release];
3).接下来要定义事件关联
在mainviewcontroller.h文件中声明变量,是为了与界面中的两个组件关联
IBOutlet UILabel*label;
IBOutlet UIButton *button;
4).声明方法
-(IBAction)clickBtn:(id)sender;
5).在.m文件中实现这个方法
-(IBAction)clickBtn:(id)sender{
NSLog(@click.....);
label.text=@Hello....;
}
6).打开IB,点击”file owner”图标,将里面的属性拖动到对应的组件上,将方法拖到按钮上,这时会显示所有事件,选中一个
2.页面跳转 与传值
1).创建一个viewcontroller,在mainview中导入此文件的接口
声明实例,如下:
CarNoViewController *carnoView=[[CarNoViewController alloc]init ];
carnoView.title=@车牌号;
carnoView.userName=@bushi;
[self.navigationController pushViewController:carnoView animated:YES];
[carnoView release];
2)在第二个viewcontroller中的.h文件中声明一个属性,如下
int age;
NSString *userName;
//注意,上面是在{}中,下面是在外面
@property (nonatomic,retain)NSString *userName;
@property int age;
在.m文件中添加
//@implementation CarNoViewController
@synthesize age;
@synthesize userName;
在第一个viewcontroller中就可以设置此实例中的此属性值了
1.通过拖动OBJECT添加类类:
在 XIB界面添加OBJECT对象,在属 性中输入类名,接着点击类名后面的一个灰色箭头,会显示此类的另一些属性
在IBOUTLET和IBACTION中输入属 性和方法
双 击刚才添加的OBJECT,会显示新添加的属性和方法,将属性和方法拖动到对应的组件中
2。为为程序添加图标图标
将一个图片文件拖到RESOURCE文件夹中,打开PLIST文件,修改里面的ICONFILE值为@icon.png即可
3.定义数组
NSArray *userNameArray=[NSArray arrayWithObjects:@Bushi,@Aobama,@Kelindun,nil];
//取数组中某个数据
label1.text=[NSString stringWithFormat:@%@,[userNameArray objectAtIndex:0]];
4.titleView添加按钮
在要添加的viewcontroller中的viewdidload添加如下代码
UIView *titleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 20)];
[titleView setBackgroundColor:[UIColor clearColor]];
显示全部