解决方案:

(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. Jenkins CI CD

    原文:https://www.sunjianhua.cn/archives/jenkins-ci-cd.html 1.安装git 以下为简单应用,适合无gitlab服务器用户. #在git服务器(19 ...

  2. 3.13. Notepad++中Windows,Unix,Mac三种格式之间的转换

    由于历史原因,导致Windows,Unix/Linux,Mac三者之间,对于文件中所用回车换行符,表示的方法,都不一样. 这就导致了很多人都会遇到回车换行符的困惑,和需要在不同格式间进行转换. 其中, ...

  3. ArcGIS Pro 中的布局

    ArcGIS Pro 中的布局 页面布局(通常简称为布局)是在虚拟页面上组织的地图元素的集合,旨在用于地图打印.常见的地图元素包括一个或多个地图框(每个地图框都含有一组有序的地图图层).比例尺.指北针 ...

  4. Step Detector and Step Counter Sensors on Android

    Step Detector and Step Counter Sensors on Android 时间 2014-03-31 11:56:00 Tech Droid 原文  http://techd ...

  5. C#实现缩放字体

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. ios之归档demo

    ios对自定义对象的归档.首先需要实现NSCoding与NSCopying接口 #import <Foundation/Foundation.h> @interface Person : ...

  7. 微信二维码扫描无法下载APK文件的解决办法

  8. Spring Scheduler定时任务 + Quartz

    原文地址: https://blog.csdn.net/revitalizing/article/details/61420556 版权声明:本文为博主原创文章,未经博主允许不得转载. https:/ ...

  9. @Autowired注解和静态方法 NoClassDefFoundError could not initialize class 静态类

    NoClassDefFoundError could not initialize class 静态类 spring boot 静态类 java.lang.ExceptionInInitializer ...

  10. cannot ignore cache if it is not cached [ArcGIS Catalog 10]

    由于我把缓存重命名,重启地图服务,再Caching中不再显示地图缓存了,我直接创建新的地图缓存,没想到出现了: 不知道怎么回事. 只好,把缓存 重新改名成原来的名字,然后,删除缓存,再建立缓存.