Use NSArray to specify otherButtonTitles?
http://stackoverflow.com/questions/1602214/use-nsarray-to-specify-otherbuttontitles
UIAlertSheet's constructor takes an otherButtonTitles parameter as a varg list. I'd like to specify the other button titles from an NSArray instead. Is this possible? i.e. I have to do this:
But since I'm generating the list of available buttons at runtime, I really want something like this:
Right now, I'm thinking that I need to have a seperate call to
That's a lot of duplicate code, but it might actually be reasonable since I have at most three buttons. How can I avoid this? |
|||
This is a year old but the solution is pretty simple ... do as @Simon suggested but do not specify a cancel button title, so:
But after adding your normal buttons, add the cancel button, like:
Now the key step is to specify which button is the cancel button, like:
We do You now also specify which button you want to be the destructive button (ie the red button) by specifying the destructiveButtonIndex (typically that will be the All of these is iOS 2.0 compatible so enjoy. |
|||||||||||||
|
Instead of adding the buttons when you initialize the UIActionSheet, try adding them with the addButtonWithTitle method using a for loop that goes through your NSArray.
|
|||||||||||||||||||||
|
addButtonWithTitle: returns the index of the added button. Set cancelButtonTitle to nil in the init method and after adding additional buttons run this:
|
|||
|
||||
You can add the cancel button and set it like this:
|
|||
I know this is an old post, but in case someone else, like me, is trying to figure this out. (This WAS answered by @kokemomuke. This is mostly a more detailed explanation. Also building on @Ephraim and @Simon) It turns out the LAST entry of addButtonWithTitle: needs to be the
|
|||
Use NSArray to specify otherButtonTitles?的更多相关文章
- iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法
今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...
- 不可变数组NSArray
//数组里面不允许存放基本数据类型,只能存放“对象” NSArray *array = [NSArray arrayWithObjects:@"周星星",@"尹天仇&qu ...
- iOS NSArray数组过滤
需求:在一个数组里面,将在这个数组中的并且在另一个数组里面的元素过滤掉. 即:在一个数组dataArray里面,将在dataArray数组中的并且在filteredArray数组里面的元素过滤掉. / ...
- NSArray 倒序 输出
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1",@"2",@"3" ...
- Fouandation(NSString ,NSArray,NSDictionary,NSSet) 中常见的理解错误区
Fouandation 中常见的理解错误区 1.NSString //快速创建(实例和类方法) 存放的地址是 常量区 NSString * string1 = [NSString alloc]init ...
- 一段可以清理NSArray中的空对象的代码(递归)
- (NSArray *)clearAllNullObject{ NSMutableArray *array = [self mutableCopy]; ;i < array.count;i++ ...
- 一些NSArray,NSDictionary,NSSet相关的算法知识
iOS编程当中的几个集合类:NSArray,NSDictionary,NSSet以及对应的Mutable版本,应该所有人都用过.只是简单使用的话,相信没人会用错,但要做到高效(时间复杂度)精确(业务准 ...
- NSArray
版权声明:本文为博主原创文章,未经博主允许不得转载. 数组是一个元素有序.元素可重复的集合,在iOS编程中经常被用到,而Foundation框架提供了数组对象.数组对象包括不可修改的数组对象NSArr ...
- 如何删除NSDictionary或NSArray中的NSNull
前段时间与某公司的技术交流,被问到一个问题,如何删除NSDictionary中的NSNull.当时在纸上写,以前太依赖Xcode编译器了,以至于方法名都写不全,最终也没写出来,我想我肯定被鄙视的体无完 ...
随机推荐
- vue 组件轮播联动
组件轮播联动我使用的是 el-carousel 组件,具体代码如下: <el-carousel trigger="click" :interval="3000&qu ...
- Y86模拟器的安装
说白了就几个指令,跟实验楼里面并不完全一样. tar -xvf sim.tar cd sim sudo apt-get install tk sudo ln -s /usr/lib/x86_64-li ...
- 剑指Offer - 九度1391 - 顺时针打印矩阵
剑指Offer - 九度1391 - 顺时针打印矩阵2013-11-24 04:55 题目描述: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 ...
- glup自动化构建工具
实现的功能包括 js压缩,css文件合并压缩并在html加版本号,压缩html文件 1.安装gulp 建议参考官网就行http://www.gulpjs.com.cn/docs/getting-sta ...
- 为什么要内存对齐 Data alignment: Straighten up and fly right
转载于http://blog.csdn.net/lgouc/article/details/8235471 为了速度和正确性,请对齐你的数据. 概述:对于所有直接操作内存的程序员来说,数据对齐都是很重 ...
- PICT:基于正交法的软件测试用例生成工具
成对组合覆盖这一概念是Mandl于1985年在测试Aad编译程序时提出来的.Cohen等人应用成对组合覆盖测试技术对Unix中的“Sort”命令进行了测试.测试结果表明覆盖率高达90%以上.可见成对组 ...
- day04_07-三个函数的区别
<?php $link = @mysql_connect('localhost','root',''); mysql_query('use test',$link); mysql_query(' ...
- input()报错:TypeError: '>=' not supported between instances of 'str' and 'int'
今天学习python基础—分支与循环,接触到了if.在练习一个if语句的时候,出现了错误. 题目是: 根据分数划分成四个级别:优秀.良好.及格.不及格,分数是72: grade = 72if grad ...
- 【转载】总结使用Unity3D优化游戏运行性能的经验
流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow Blade>已经将在标准iPhone和iPad设备上实现每秒60帧视为一个重要目标. 以下是我们在紧凑的优化过程中 ...
- NOIP2018 集训(三)
A题 Tree 问题描述 给定一颗 \(n\) 个点的树,树边带权,试求一个排列 \(P\) ,使下式的值最大 \[\sum_{i=1}^{n-1} maxflow(P_i, P_{i+1}) \] ...