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系统中发现,当输入内容后,点 ...
随机推荐
- mysql大文本数据类型的使用需要考虑实际情况
mysql数据类型简介(http://news.newhua.com/news1/program_database/2008/618/08618103911CD92HJ6CKI2I9I0AH5CGK1 ...
- NSNotificationCenter消息注册与撤销
苹果的消息机制是个非常好用的东西,当需要在类的各个实例之间传递消息或者写一些事件驱动的程序时,绝对是个不错的工具.但是使用时一不小心就会造成引用已经被dealloc的对象的错误,引起程序崩溃.于是,在 ...
- WordPress主题开发:WP_Query使用分页实例
functions.php加入 <?php function lingfeng_custom_pagenavi( $custom_query,$range = 4 ) { global $pag ...
- Fix "Drives are running out of free space" Error in SharePoint Health Analyzer
前言 最近帮助用户做健康检查,用户发现事件查看器(EventView)里面有很多错误,有一个就是"Drives are running out of free space",而且每 ...
- 64位Windows操作系统中的注冊表
x64系统上有x64.x86两种注冊表,记录下. 64 位Windows系统中的注冊表分为 32 位注冊表项和 64 位注冊表项.很多 32 位注冊表项与其对应的 64 位注冊表项同名. 在64位版本 ...
- unity 打包资源及网络请求资源包
第一步 导包 在Assets新建一个Editor目录 新建一个Test类 using UnityEngine; using System.Collections; using UnityEditor; ...
- 实用ExtJS教程100例-008:使用iframe填充ExtJS Window组件
上面两节中我们分别演示了ExtJS Window的常用功能 和 如何最小化ExtJS Window组件,在这篇内容中我们来演示一下如何使用iframe填充window组件. 思路很简单,首先创建一个w ...
- ubuntu php 安装
---apache2sudo apt-get install apache2 ---phpsudo apt-get install libapache2-mod-php5 php5 php5-gd p ...
- selector属性介绍
本文来自:http://blog.csdn.net/brokge/article/details/9713041 简介: 根据不同的选定状态来定义不同的现实效果 分为四大属性: android:sta ...
- 《App,这样设计才好卖》
<App,这样设计才好卖> 基本信息 作者: (日)池田拓司 译者: 陈筱烟 丛书名: 图灵交互设计丛书 出版社:人民邮电出版社 ISBN:9787115359438 上架时间:2014- ...