iOS开发技巧 - 使用Alerts和Action Sheets显示弹出框
解决方案:
(Swift)
使用UIAlertController类
(Objective-C)
使用UIAlertView类
代码:
(Swift)
import UIKit
class ViewController: UIViewController {
// 1. define the variable that will hold our alert controller
var controller:UIAlertController?
override func viewDidLoad() {
super.viewDidLoad()
// 2. start constructing a simple alert view controller using the alert view style
controller = UIAlertController(title: "Title",
message: "Message",
preferredStyle: .Alert)
// 3. simply print out a text to the console when pressed
let action = UIAlertAction(title: "Done",
style: UIAlertActionStyle.Default,
handler: {
(paramAction:UIAlertAction!) in
println("The Done button was tapped")
})
// 4. add the action that we created to the alert controller
controller!.addAction(action)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// 5. present the alert controller
self.presentViewController(controller!, animated: true, completion: nil)
}
}
(Objective-C)
#import "ViewController.h" @interface ViewController () <UIAlertViewDelegate>
@end @implementation ViewController
... - (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]; self.view.backgroundColor = [UIColor whiteColor]; NSString *message = @"Are you sure you want to open this link in Safari?"; UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Open Link"
message:message
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil]; [alertView show];
} - (void) alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex]; if ([buttonTitle isEqualToString:@"Yes"]){
NSLog(@"User pressed the Yes button.");
}
else if ([buttonTitle isEqualToString:@"No"]){
NSLog(@"User pressed the No button.");
}
}
iOS开发技巧 - 使用Alerts和Action Sheets显示弹出框的更多相关文章
- C#使用Xamarin开发可移植移动应用(5.进阶篇显示弹出窗口与通讯中心)附源码
前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 没啥好说的 ...
- iOS开发技巧系列---详解KVC(我告诉你KVC的一切)
KVC(Key-value coding)键值编码,单看这个名字可能不太好理解.其实翻译一下就很简单了,就是指iOS的开发中,可以允许开发者通过Key名直接访问对象的属性,或者给对象的属性赋值.而不需 ...
- 【转】几点 iOS 开发技巧
[译] 几点 iOS 开发技巧 原文:iOS Programming Architecture and Design Guidelines 原文来自破船的分享 原文作者是开发界中知晓度相当高的 Mug ...
- 李洪强iOS开发之-实现点击单行View显示和隐藏Cell
李洪强iOS开发之-实现点击单行View显示和隐藏Cell 实现的效果: .... ....
- 【Unity技巧】自定义消息框(弹出框)
写在前面 这一篇我个人认为还是很常用的,一开始也是实习的时候学到的,所以我觉得实习真的是一个快速学习工程技巧的途径. 提醒:这篇教程比较复杂,如果你不熟悉NGUI.iTween.C#的回调函数机制,那 ...
- Add an Action that Displays a Pop-up Window 添加显示弹出窗口按钮
In this lesson, you will learn how to create an Action that shows a pop-up window. This type of Acti ...
- ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前
原文:ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前 背景 当数据量大.查询条件复杂,多样多的时候,我们可能需要单独做一个查询界面,当用户选择设置了相关的 ...
- 关闭ios弹出框:“would like to use your current location”
图一: 图二: 使用cordova生成ios项目,首次打开获取用户定位时会弹出两次对话框,关闭图二中对话框方法: document.addEventListener("deviceready ...
- 微信公众号弹出框在IOS最新系统中点击键盘上的“完成”导致事件无法触发问题
微信公众号弹出框在IOS最新系统中点击键盘上的"完成"导致事件无法触发问题 问题描述 微信公众号中有项功能是弹框模态框,输入信息后保存操作.但是在IOS系统中发现,当输入内容后,点 ...
随机推荐
- 怎样连接REDIS服务端
怎样连接REDIS服务端 REDIS服务器是TCP/IP SERVER,因此客户端要访问,必须先同服务器建立SOCKET连接,然后才可以发送各种REDIS COMMAND(指令). 首先要引用单元文件 ...
- IOS开发之——objective-c与javascript交互
原文:http://blog.csdn.net/pjk1129/article/details/6936545 在写 JavaScript 的时候,可以使用一个叫做 window 的对象,像是我们想要 ...
- 关于iosApp审核问题
求各位大神指导!!!!我上周app打包上传给APPstore准备发布,可是苹果官方发来邮件,说我引用了非公有选择,原文如下: Non-public API usage: The app referen ...
- 快速将wax配置到项目中进行lua开发
通过Finder浏览到你保存该项目的文件夹.创建三个新的文件夹:wax.scripts和Classes. 第一:首先,下载源代码的压缩包.Wax放在GitHub上(https://github.com ...
- nginx网站攻击防护
1.上上个月架构全部迁移上云以后,总的来说比较稳定,业务量也上来,可爱的坏人也来了,7X24小时不停恶意攻击我的网站,第一次收到报警是网站流入流量1分钟以内连续3次超过1000000bps,换算下1M ...
- Weblogic跨域session冲突解决办法
一.现象: 在WebLogic中,有两个不同域A(端口:9000)和B(端口:8000),应用CA在域A中,应用CB在域B中,进行如下操作: 1.先登录应用CA,再登录应用CB,然后,切换回应用CA, ...
- Excel 2016 Power View选项卡不显示的问题
https://zhuanlan.zhihu.com/p/43543442 PowerView是Excel中的Power系列插件之一,可以基于excel制作交互式仪表板. 初学者在使用Power Vi ...
- [转]php curl经典最常用的5个例子
转自: http://www.jb100.net/html/content-22-821-1.html php curl常用的5个例子 我用php ,curl主要是抓取数据,当然我们可以用其他的方法来 ...
- 启明星会议室系统与Office365集成说明
在本文,我们将介绍如何配置Office365,以便改系统能够支持启明星会议室预定系统. In this article, we will introduct how to config microso ...
- Reloading Java Classes 201: How do ClassLoader leaks happen? Translation
The original link : http://zeroturnaround.com/rebellabs/rjc201/ From ClassLoaders to Classes 从ClassL ...