本章节将会介绍两个内容:
1.如何新建一个页面,并且从我们已有的页面跳转过来的。
2.在新建页面增加一个button,和一个lable,点击button的时候,修改lable的值
第一步:
将View Controller拖拽到我们之前创建的Main.storyboard中,这样就新建立了一个页面了。
然后建立这个页面和ViewController代码的关联,在Custom Class中填入我们需要的类名。
这样就就已经完成了页面的创建了。
第二步,建立跳转。
按着ctrl键+点击上一个页面的button键,链接到我们新的页面,选择Push(其他含义以后讲解)
这样就完成了,页面的跳转,点击这个button就会跳转到我们新的页面。
第三步:建立button和lable
这一步很简单了,直接拖拽进来一个button和一个lable就可以了
第四步:添加代码button点击触发lable内容改变
首先是连接lable与代码,我们需要在.h中设置一个输出口
@property (nonatomic,retain)IBOutletUILabel *lable;
然后再.m中
@synthesize lable;
- (IBAction)buttonPressed:(id)sender;
-(IBAction)buttonPressed:(id)sender
{
NSString *title = [sendertitleForState:UIControlStateNormal];
NSString *newText = [[NSStringalloc]initWithFormat:@"%@ button pressed.",title];
lable.text = newText;
NSLog(@"statusText =%@",newText);//log
[newText release];
}
