zoukankan      html  css  js  c++  java
  • 【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出来了!!

    
    
  • 相关阅读:
    原生js实现购物车相关功能
    js+css让背景图片动起来
    彻底搞清楚rgba与opacity/filter的区别
    国家对五险一金的详细缴纳说明
    原生js+css实现二级伸缩菜单
    原生js实现table表格的各行变色功能
    原生js实现二级导航功能
    app下载文件,保存文件,展示文件(以图片文件为例)
    实现锚点跳转的两种方式及注意事项
    vue刷新页面及注意事项
  • 原文地址:https://www.cnblogs.com/bvin/p/2836501.html
Copyright © 2011-2022 走看看