解决方案:

(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. ListBox使用

    一.什么是ListBox? ListBox 是一个显示项集合的控件.一次可以显示 ListBox 中的多个项. ListBox继承自ItemsControl,可以使用Items或者ItemsSourc ...

  2. C语言控制结构

    C语言流程控制 一.流程控制结构 (1)顺序结构:按书写顺序执行每一条语句. (2)选择结构:对给定的条件进行判断,根据判断结果决定执行哪一段代码. (3)循环结构:在给定条件成立的情况下,反复执行某 ...

  3. Java 遍历类中的属性

    public static void testReflect(Object model) throws NoSuchMethodException, IllegalAccessException, I ...

  4. git push origin master:master

    $git push origin master:master (在local repository中找到名字为master的branch,使用它去更新remote repository下名字为mast ...

  5. cocos2d-x 清空缓存

    如场景切换  在内存吃紧的情况下 我们可以选择 先清理一下缓存 // 清空缓存 CCDirector::sharedDirector()->purgeCachedData();

  6. bean validation 技术规范

    Bean Validation 技术规范特性概述 张 冠楠 和 陈 志娴2011 年 3 月 24 日发布 WeiboGoogle+用电子邮件发送本页面 2 概述 Bean Validation 规范 ...

  7. 多个so中模板单例的多次实例化

    在Android打包项目时,发现登录功能不能使用了,logcat中也没发现什么问题,最后一行一行log定位到了问题.原来是一个so文件中的构造函数被初始化二次!   这个单例是通过继承模板来实现的(暂 ...

  8. http链接的性能测试工具httping

    安装:MAC环境下使用brew进行安装      brew  install  httping 使用参数: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  9. hdu 2049 不easy系列之(4)——考新郎

    不easy系列之(4)--考新郎 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. docker 删除无用的镜像文件的命令小计

    df -h  查看当前服务器的内存情况 docker system prune  删除无用镜像文件命令 执行ok之后,再次查看内存情况.