现在的位置: 首页 > 综合 > 正文

ios学习笔记:UIAlertView的使用

2018年01月11日 ⁄ 综合 ⁄ 共 621字 ⁄ 字号 评论关闭

按照第一个教程建立一个ios程序,选择viewcontroller.xib文件

在xib文件中拖入一个button按钮,如下图


双击button按钮,或是在右边编辑,将button按钮改名为hello world


选择run左上角的运行按钮,打开ios模拟器如图


这时我们点击hello world按钮,没什么反应,接下来回到项目,选择右上角Editor,中间,这时会出现如下界面

左边是xib文件右边是viewController.h文件,接下来,选中button按钮,点击鼠标右键,拖动到viewController.h文件中如图


在Connection中选择Action,在name中输入内容,随便输入,这里我就随便输入了,然后点击Connect


这时选择viewcontroller.m文件 在

- (IBAction)button:(id)sender {

}中输入以下内容,

- (IBAction)button:(id)sender {

     UIAlertView *helloWorld = [[UIAlertView alloc]initWithTitle:@"My First App" message:@"Hello, World!"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

     [helloWorld show]; 

}

这时点击运行,启动ios模拟器,点击按钮,出现东西了,太神奇了,教程到此结束

抱歉!评论已关闭.