【ios6.0 自学瞎折腾】(二)控件交互和对话框

 

上篇是错了,故事模板再创建的时候可以不勾选,主要创建出来的项目就会有xib文件了。

下面是程序配置界面

如上篇,拖入一个按钮,双击改名。接下来很重要一步喔,选中这个按钮,按住你键盘上的control键,记住是ctrl而不是苹果键喔,然后用鼠标拖动到下图处,这时会有一个箭头指向File's Owne,然后会弹出你写的方法。

选中这个按钮,我们可以查看这个按钮的所有事件:

方法怎么写呢??

首先再ViewController.h里申明一个方法;

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
-(IBAction)showMessage;//返回IBAction类型
@end

然后在ViewController.m里写具体方法实现:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)showMessage
{
    UIAlertView *mAlert = [[UIAlertView alloc]initWithTitle:@"第一个应用demo" message:@"Hello world" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [mAlert show];
}

@end
UIAlertView alloc:给mAlert分配内存空间;
initWithTitle:message:delegate:cancelButtonTitle:otherButtonTiles:;初始化mAlert
带标题,消息,取消确定按钮等参数,是不是有点像android呢?呵呵!

然后给mAlert对象发送show消息,这样就把对话框给show出来了!!


posted @ 2012-12-27 22:16  bvin  阅读(381)  评论(0编辑  收藏  举报