【iOS】按钮点击弹窗

拖入一个Round Rect Button,并将Button的文字修改成“点击弹窗”


将ViewController.h修改为如下代码,实则在ViewController.h中添加了一行-(IBAction)messageBoxShow;,注册messageBoxShow这个函数。类似于C语言使用函数之前需要在头文件声明这个函数头。

//
//  ViewController.h
//  MessageBox
//
//  Created by pc on 17-5-13.
//  Copyright (c) 2017年 pc. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

-(IBAction)messageBoxShow;

@end
将ViewController.m修改为如下的代码,实则添加-(IBAction)messageBoxShow函数,并完成这个函数的内容。

//
//  ViewController.m
//  MessageBox
//
//  Created by pc on 17-5-13.
//  Copyright (c) 2017年 pc. All rights reserved.
//

#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)messageBoxShow{
    UIAlertView *uiAlertView=[[UIAlertView alloc]initWithTitle:@"弹窗标题栏"message:@"弹窗消息"delegate:nil cancelButtonTitle:@"确定!" otherButtonTitles:nil];
    [uiAlertView show];
    
}

@end
回到MainStoryboard.storyboard,单击按钮之后,按着Ctrl出现蓝色箭头,将其拖到View Controller,松开鼠标和Ctrl,指定点击事件。


之后会弹出菜单,选择Sent Events下面的messageBoxShow函数。


点击运行之后,点击按钮则可以弹窗,如下图所示。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值