[ios]i对话框UIActionSheet和UIAlertView用法

UIActionSheet和UIAlertView在iOS中,都是弹出一个对话框,用户必须点击上面的按钮后才能执行其他操作。
下图是UIActionSheet,对话框显示在底部:

下图是AlertView,显示在屏幕正中:

当按钮在两个以内时,按钮是水平显示的,当超过两个时,会垂直显示。
相当代码:
首先在viewController h头文件添加UIActionSheetDelegate,UIAlertViewDelegate协议,如下:

1
2
#import <UIKit/UIKit.h>
@interface TESTViewController : UIViewController <UIActionSheetDelegate,UIAlertViewDelegate>

以下代码在ViewController.m文件中
打开ActionSheet对话框:

1
2
    UIActionSheet *sheet=[[UIActionSheet alloc] initWithTitle:@"你确定?" delegate:self cancelButtonTitle:@"不确定" destructiveButtonTitle:@"非常确定" otherButtonTitles: nil];
    [sheet showInView:self.view];

接收ActionSheet点击事件,以及打开AlertView对话框、接收AlertView点击事件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    //该方法由UIActionSheetDelegate协议定义,在点击ActionSheet的按钮后自动执行
    NSString *string=[NSString stringWithFormat:@"你点击了 %@",[actionSheet buttonTitleAtIndex:buttonIndex]];
 
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:string delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
    alert.alertViewStyle=UIAlertViewStyleDefault;
    //UIAlertViewStyleDefault 默认风格,无输入框
  //UIAlertViewStyleSecureTextInput 带一个密码输入框
  //UIAlertViewStylePlainTextInput 带一个文本输入框
  //UIAlertViewLoginAndPasswordInput 带一个文本输入框,一个密码输入框
    [alert show];
 
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    //该方法由UIAlertViewDelegate协议定义,在点击AlertView按钮时自动执行,所以如果这里再用alertView来弹出提//示,就会死循环,不停的弹AlertView
    NSString * string=[NSString stringWithFormat:@"你点击了 %@",[alertView buttonTitleAtIndex:buttonIndex]];
    //    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:string delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    //    [alert show];
    NSLog(@"%@",string);
  
//NSLog(@"输入 %@",[[alertView textFieldAtIndex:0] text]); 获取第一个文本框输入的文本,如果没有文件框,会异常,索引从0开始
 
}

 

UIAlertView -(警告框)方法总结 UIAlertView -(警告框)方法总结 在IOS8之后,UIAlertView和UIActionSheet这两个控件被UIAlertController代替,但是这两个控件依然可以使用。这篇博客主要总结UIAlertView的常用方法。 阅读详情

相关推荐

IOS开发指南之使用UIAlertController与UIAlertView显示提示框

1.UIAlertController支持IOS9或者更高版本。2. UIAlertView支持IOS9之前版本。

1133

iOS开发 对话框UIActionSheet和UIAlertView用法

UIActionSheet和UIAlertView在iOS中,都是弹出一个对话框,用户必须点击上面的按钮后才能执行其他操作。 下图是UIActionSheet,对话框显示在底部: 下图是AlertView,显示在屏幕正中: 当按钮在两个以内时,按钮是水平显示的,当超过两个时,会垂直显示。 相当代码: 首先在viewController h头文件添加UIActionSheetDel

smallsky_keke的专栏 2247

基于PSINS的INS/NHC/ODO组合导航仿真全解析

组合导航通过多传感器融合克服单一导航系统的局限,是车辆自主定位的关键技术。其中惯性导航(INS)依靠陀螺仪与加速度计积分推算运动状态,但误差随时间累积;GNSS提供绝对位置,却在城市峡谷中易受多径效应和遮挡影响导致定位漂移。卡尔曼滤波作为信息融合核心,将不同量测按统计特性加权,实现优势互补。基于PSINS开源工具箱搭建的SINS/GNSS/ODO/NHC组合导航仿真,能够在GNSS失锁条件下利用非完整约束和里程计抑制惯性误差发散,广泛应用于无人驾驶、物流车辆自主定位等场景。本文围绕PSINS仿真环境,详细拆

weixin_29044713的博客 253

iOS开发——ActionSheet的使用与弹出选择对话框

在我们的iOS开发中,常会见到如下界面的需求:。也就是点击按钮,出现选择提示框,我们今天使用两种方式(ActionSheet和AlertController)来实现该功能。【使用ActionSheet实现】(1)实现代码如下:#import "ViewController.h" @interface ViewController () @end @implementation ViewCon

乞力马扎罗的雪CYF的博客 9652

C#与Vector XL驱动库实战:CAN通道配置与端口访问详解

本文详细解析了使用C#调用Vector XL驱动库进行CAN总线通信开发的核心步骤。重点阐述了如何通过XL_GetDriverConfig获取硬件通道信息,并厘清channelMask与accessMask的区别与转换关系,最终指导开发者正确使用XL_OpenPort函数配置并打开CAN端口,为构建稳定的汽车电子测试与诊断应用奠定基础。

weixin_28452161的博客 362

航天仿真必看:如何用SOFA库实现高精度GCRS-ITRS坐标转换?避坑指南

本文深入解析了航天仿真中高精度GCRS-ITRS坐标转换的关键技术,重点介绍了SOFA库在天球系与轨道系转换中的权威应用。通过对比传统方法的误差来源,详细阐述了SOFA库的转换算法优势、工程实现步骤及误差控制策略,为航天器轨道仿真提供毫米级精度的解决方案。

7h6j5k4l3的博客 850

【弹出对话框以及提示UIAlertView不可用的解决办法 Objective-C语言】

【弹出对话框 Objective-C语言】

madoca的博客 1387

Ardupilot姿态控制详解(完结篇)

本文主要是对过去写的一些APM中姿态控制流程及函数博文的汇总。 按照之前写的博文以及个人认为的学习顺序,给出APM姿态控制器的学习顺序如下: APM姿态旋转理论基础 Ardupilot姿态控制器 PID控制流程(整定后的P控制器) 详解APM的开方控制器sqrt_controller Ardupilot前馈及平滑函数input_euler_angle_roll_pitch_yaw解析 Ardupilot倾转分离函数thrust_heading_rotation_angles Ardupilot四元数姿态控制

moumde的博客 7023

IOS 警告框 (UIAlertView)的使用方法

1.普通警告框 IOS的SDK中提供了一个方便的类库UIAlertView,配合着不同参数来使用此类可以做出大多数的警告框,如下代码是IOS最简单的警告框。 1 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"你好" message:@"我是普通警告框" delegate:nil cancelButtonTitl...

weixin_33704591的博客 7284

2026零成本私有化:OpenClaw一键搭建Discord/Telegram智能机器人,数据不出本地,永久免费替代ChatGPT

如果内置的功能不能满足你的需求,你可以很容易地添加自己的自定义工具。public string Description => "查询指定城市的天气";// 调用天气API获取天气信息return $"city今天的天气是晴,温度25度";// 注册工具今天北京的天气怎么样?大模型的选择很重要:不要盲目追求大参数的模型。对于大多数场景来说,7B参数的模型已经足够用了,而且速度快,内存占用低。上下文长度不要设置太大:上下文长度越大,内存占用越高,推理速度越慢。

2601_94871597的博客 259

C#里使用NModbus来创建一个TCP从站服务

摘要:本文介绍了一个用C#实现的Modbus TCP从站服务器,基于.NET Framework 4.6.1开发。代码使用NModbus库创建TcpListener和ModbusSlaveNetwork,支持设置IP地址、端口号和从站ID。服务器实现了数据存储初始化功能(包括线圈和保持寄存器),并提供了启动/停止操作的UI界面和日志记录功能。该解决方案适用于需要调试Modbus TCP协议的场景,特别适合无法升级到更高版本.NET Framework的环境。

大坡3D软件开发 477

UIAlertView和UIActionSheet

UIAlertView和UIActionSheet是iOS自带的弹出式对话框。当这俩个控件出现时,用户无法与其他控件进行交互。 两个区别在于: UIAlertView是显示在屏幕中央的,而UIActionSheet是显示在底部的按钮列表。 UIAlertView的用法非常简单: 1.创建UIAlertView,指定该对话框的标题、消息内容、以及该对话框包含的按钮信息。如果要监听按钮点击警告框

小王的技术窝 1372

C# 与华中数控设备通信:数控机床自动化控制与实时监测系统

华中数控系统与C#通信开发指南 核心要点 通信基础 支持串口(RS232/RS485)和以太网两种连接方式 协议选择:通用Modbus协议或华中自定义HNC协议 关键数据映射表明确各参数对应的寄存器地址和功能码 系统架构 四层架构:设备层→通信层→业务层→应用层 包含实时数据采集、指令下发、状态监控、异常处理全流程 支持Modbus和HNC协议动态切换 代码实现 串口通信使用NModbus库简化开发 提供连接管理、数据读取、指令下发完整示例 包含异常处理和超时重连机制 应用价值 实现数控机床远程监控和自动化

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 2018

【学习ios之路:UI系列】UIAlertView. UIActionSheet 和 UIAlertController

1.UIAlertView ①简单无代理模式,代码如下: UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"这是一个警告" delegate:nil cancel

Forever_YouSay 3377

【AUTOSAR-RTE】-1-聊一聊RTE(Run-Time Environment)

RTE(Run-Time Environment)是AUTOSAR ECU架构的核心。

「汽车电子助手」的博客 6501

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

UIAlertView和UIActionSheet类在IOS8以后的改动

iOS 8的新特性之一就是让接口更有适应性、更灵活,因此许多视图控制器的实现方式发生了巨大的变化。全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸变化效果(比如说旋转)中发挥了重要的作用,它有效地节省了程序员们的工作量(天地良心啊)。还有,某些旧的UIKit控件也同样发生了许多变化,比如说Alert Views、Action Sheets、Po

topws1的博客 449

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

IOS提示控件UIActionSheet,UIAlertView

实际显示效果图(UIActionSheet) 实现代码: @interfaceContactsTableViewController()<UIActionSheetDelegate>//此处要添加代理 -(IBAction)logout:(id)sender; ...

110

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

UIActionSheet,UIAlertView技术分享

UIActionSheet [objc]view plaincopy #import"FirstViewController.h" @interfaceFirstViewController()<UIActionSheetDelegate,UIAlertViewDelegate> @property(re...

aqlomr7170的博客 111

ios基础控件UIAlertView与UIActionSheet

1.UIAlertView 首先来看下UIAlertView的实现效果图: 第一步通过点击外部按钮弹出提醒对话框 - (IBAction)showAlertView:(id)sender { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"标题" message:@"提醒内容" delegate:self canc

陈正的博客 570

IOS-UIAlertView和UIActionSheet

IOS中两大控件:UIAlertView和UIActionSheet UIAlertView是在屏幕中央弹出一个消息框,该消息框可以用来做消息提示,也可以让用户选择不同选项。 UIActionSheet是在屏幕底端弹出一个消息框,功能类似UIAlertView,不过两者除了位置不一样外,其外观也有出入。为了能够响应UIAlertView和UIActionSheet,需要设定其代理,而对

Arbboter的专栏 1698

介绍UIALertView和UIActionSheet的用法。

介绍UIALertView和UIActionSheet的用法。 write by Xingchen’s sky 1:构建一个简单的警告框: UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"xingchen" message:@"message"       delegate:nil      cancelButtonTi

计算机学习园 762

对话框UIAlertView

对话框学习UIAlertView 当一个control中有多个alertdialog的时候,绑定alertdialog的tag来区分不同的alertdialog #import "ViewController.h" @interface ViewController () - (IBAction)showAlertDialog; - (IBAction)showActionSheet; @

smilebigdear的专栏 433

Iphone之UIAlertView和UIActionSheet

UIAlertView和UIActionSheet的用法很简单,直接看代码: 1.UIAlertView: .h头文件: #import @interface DialogControl : UIViewController {//注意要实现这个协议 UIAlertView *alertView1;//多个dialog的点击事件需要区分是哪一个dialog UIAl

RiverAM的专栏 1386

iOS学习笔记—— UIAlertView 和 UIActionSheet 的使用

iOS程序中的Action   Sheet就像Windows中的 “确定-取消”对话框一样,用于强制用户进行选择。当用户将要进行的操作具有一定危险时,常常使用Action Sheet对用户进行危险提示,这样,用户有机会进行取消操作。Alert相当于Windows中的Messagebox,跟Action Sheet也是类似的。不同的是,Alert可以只有一个选择项,而Action Sheet却至少要

狂飙的蜗牛 的专栏 1045

iOS UIAlertView和UIActionSheet的用法

这篇文章主要学习alertview 和 actionsheet这两个控件的使用。Action Sheet是从底部弹出,上面有2个或者2个以上的选项供用户选择,Alert就是一个警告框,上面有1个或者1个以上的按钮供用户进行选择。 (说明:其实这两个不是控件,而是ios 中的两个类,这里暂且这么叫吧。这2个类定义了2种不同类型的用于和用户交互的弹出框) 首先,使用这两个类要使用到其代理,UIAl

小邓笔记 3485
上一篇: [ios]获取网络状态
下一篇: [ios]转UITableView学习笔记
iPoolo
博客等级 码龄17年 2粉丝 168原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值