解决方案:

(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显示弹出框的更多相关文章

  1. C#使用Xamarin开发可移植移动应用(5.进阶篇显示弹出窗口与通讯中心)附源码

    前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 没啥好说的 ...

  2. iOS开发技巧系列---详解KVC(我告诉你KVC的一切)

    KVC(Key-value coding)键值编码,单看这个名字可能不太好理解.其实翻译一下就很简单了,就是指iOS的开发中,可以允许开发者通过Key名直接访问对象的属性,或者给对象的属性赋值.而不需 ...

  3. 【转】几点 iOS 开发技巧

    [译] 几点 iOS 开发技巧 原文:iOS Programming Architecture and Design Guidelines 原文来自破船的分享 原文作者是开发界中知晓度相当高的 Mug ...

  4. 李洪强iOS开发之-实现点击单行View显示和隐藏Cell

    李洪强iOS开发之-实现点击单行View显示和隐藏Cell 实现的效果:  .... ....

  5. 【Unity技巧】自定义消息框(弹出框)

    写在前面 这一篇我个人认为还是很常用的,一开始也是实习的时候学到的,所以我觉得实习真的是一个快速学习工程技巧的途径. 提醒:这篇教程比较复杂,如果你不熟悉NGUI.iTween.C#的回调函数机制,那 ...

  6. 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 ...

  7. ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前

    原文:ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前 背景 当数据量大.查询条件复杂,多样多的时候,我们可能需要单独做一个查询界面,当用户选择设置了相关的 ...

  8. 关闭ios弹出框:“would like to use your current location”

    图一: 图二: 使用cordova生成ios项目,首次打开获取用户定位时会弹出两次对话框,关闭图二中对话框方法: document.addEventListener("deviceready ...

  9. 微信公众号弹出框在IOS最新系统中点击键盘上的“完成”导致事件无法触发问题

    微信公众号弹出框在IOS最新系统中点击键盘上的"完成"导致事件无法触发问题 问题描述 微信公众号中有项功能是弹框模态框,输入信息后保存操作.但是在IOS系统中发现,当输入内容后,点 ...

随机推荐

  1. C#各种泛型集合体验

    本篇体验除Queue<T>和Stack<T>之外的其它泛型集合. SortedList<TKey, TValue> SortedList<TKey, TVal ...

  2. WordPress主题开发:get_term_by和get_term_link

    学习目的: 某一个分类的名称.别名.和id都可以到后台自己去找,但这样找比较麻烦还容易看错,wordpress提供了下面两个函数get_term_by和get_term_link,只要提供别名.名称或 ...

  3. 超人前传第一至十季/全集Smallville迅雷下载

    超人前传 第一至十季 Smallville Season 1-10 (2001-2010)本季看点:CW台的长寿剧<超人前传>在以帅哥靓女征服观众了这么多年后,也终于进入尾声,该剧将于今年 ...

  4. [Android Pro] 组件化:企业级大型项目必经之路

    cp : https://www.csdn.net/article/2011-02-11/291667 摘要:超过一年以上.活跃开发的项目往往到后期陷入了一些共性的问题: 构建速度慢,往往生成一次最终 ...

  5. Java SPI机制原理和使用场景

    SPI的全名为Service Provider Interface.这个是针对厂商或者插件的.一般来说对于未知的实现或者对扩展开放的系统,通常会把一些东西抽象出来,抽象的各个模块,往往有很多不同的实现 ...

  6. [转]MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践

    转自:http://heylinux.com/archives/1004.html Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中,由单 ...

  7. 自适应尺寸变化的meanshift跟踪

    近期在看meanshift方面的文章,看了一篇博文对这篇文章<Robust scale-adaptive meanshift for tracking>寄予非常高的评价,所以把这篇文章简要 ...

  8. verilog语法实例学习(10)

    常用的时序电路介绍 T触发器和JK触发器 在D触发器输入端添加一些简单的逻辑电路,可以生成另一种类型的存储元件.比如下图所示的T触发器.该电路有一个上升沿触发的触发器和两个与门,一个或门,以及一个反相 ...

  9. opengl 教程(24) shadow mapping (2)

    原帖地址:http://ogldev.atspace.co.uk/www/tutorial24/tutorial24.html 本篇教程中,我们通过shadowmap来实现阴影渲染. 我们知道shad ...

  10. CentOS6.4下安装Chrome

    因为蛋疼的glibc问题,(我就纳闷了,为何CentOS支持的glibc的版本就那么低呢,害得我至今还没把genymotion安装上), Chrome浏览器一直没安装上,不过终于找到了解决方案,安装派 ...