我似乎遇到了类似于一个未解决的问题中的问题:UIAlertController解雇他的presentViewController
我在普通的UIViewController上呈现模态视图控制器.然后我在该模态视图控制器上弹出警报.当我按"ok"关闭警报(使用下面的代码生成)时,模态视图控制器也被解除.
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action{
[self dismissViewControllerAnimated: YES completion: nil];}];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Sign up problem."
message:@"Some fields are empty. Please check your inputs and try again."
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
我该如何解除警报?
我意识到我可以通过使用导航控制器类型设置而隐藏导航栏来避免这个问题,所以我得到了与模态视图控制器相同的感觉,但这看起来很傻.谢谢.
我已将TouchID合并到我的应用中LAContext,如下所示:

但是,我想要从"输入密码"更改按钮标题的名称,以输入"输入安全代码"(或类似的东西),如下所示:

如何更改按钮标题?
这是LAContext 文档,这是我的代码:
var touchIDContext = LAContext()
if touchIDContext.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &msgError) {
touchIDContext.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: touchIDMessage) {
(success: Bool, error: NSError!) -> Void in
if success {
println("Success")
} else {
println("Error: \(error)")
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要在Action表项中添加图像UIAlertController.我添加使用:
UIImage *image = [UIImage imageNamed:@"icon.png"];
[alertAction setValue:image forKey:@"image"];
Run Code Online (Sandbox Code Playgroud)
结果如下:

问题是: 我需要图像和文本居中对齐并调整取消按钮的高度
我该怎么做,请分享一些代码.
谢谢!
我在为我设置文本字段时遇到一些问题UIAlertController.
我正在使用此代码添加舍入textfield到alertcontroller:
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"placeholder";
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
Run Code Online (Sandbox Code Playgroud)
但结果如下:

如何删除外边框和背景颜色?所以它看起来像他们在本教程中所拥有的:http://useyourloaf.com/blog/2014/09/05/uialertcontroller-changes-in-ios-8.html.
谢谢!
所以我有一个使用以下代码创建的UIAlertController:
let alertView = UIAlertController(title: "Warning", message: "You have made changes to \(workoutTemplate!.name). Do you wish to overwrite these changes?", preferredStyle: UIAlertControllerStyle.ActionSheet)
alertView.addAction(UIAlertAction(title: "Yes, Overwrite", style: UIAlertActionStyle.Destructive, handler: {(alert: UIAlertAction!) in
//... some code
}))
alertView.addAction(UIAlertAction(title: "No, Rename", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in
//..some more code
}))
self.presentViewController(alertView, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我已将警报控制器设置为按下按钮显示,但警报会自动消失:

编辑:发现问题!这对我来说是一个愚蠢的疏忽.上面的代码在交换机中.转换后,我立刻打了个self.dismissViewController()电话.我遗漏了一个else声明,VC在呈现AlertController后试图解雇自己.但是,由于AlertController在此调用时位于导航堆栈的顶部,因此它被解除了.
如何UITextview在一个内部制作多行可编辑文本UIAlertController?UITextfield支持单行,我们需要在弹出窗口中创建一个多行文本编辑框.
我有一个UIAlertController从提出UIViewController这是在推UINavigationController作为最后UIViewController.这里面UIAlertViewController有一个UITextField.
我的问题是,当我选择UITextField键盘显示,但UIAlertViewController保持居中,并部分隐藏在键盘下.
我的代码看起来像这样:
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Enter Your PIN" message:@"Please enter your PIN!" preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
[textField setSecureTextEntry:YES];
}];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"Confirm"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) { }];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:okAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
在我的swift应用程序中,我有一个带有单个按钮的UIViewController.
此按钮调用一个函数,该函数调用在3秒后消失的弹出窗口.此外,在此之后它会向控制台输出一条消息.该函数的代码如下:
func showAlertMsg(title: String, message: String){
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
self.presentViewController(alertController, animated: true, completion: nil)
let delay = 3.0 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), {
alertController.dismissViewControllerAnimated(true, completion: nil)
print("popup disappeared")
})
}
Run Code Online (Sandbox Code Playgroud)
这很好,但我想介绍一些改进.我想添加一个按钮,立即取消此弹出窗口,然后避免在控制台中显示该消息.有没有办法向用户显示这样的弹出窗口?另外 - 有没有一种方法可以在这个弹出消息中显示计数器的秒数,这个计数器显示弹出消失之前还剩多少时间?
我有一个警报视图,我试图在照片视图上呈现.
照片显示在列表中,可以推送到全屏视图.
照片视图以编程方式显示.我认为这是导致问题的原因,因为警报视图试图在已经呈现的(照片)视图之上呈现另一个视图.
警报视图正在尝试显示,但是收到此错误:
Warning: Attempt to present <UIAlertController: 0x147d2c6b0> on <LiveDeadApp.ListViewController: 0x147d614c0> which is already presenting (null)
Run Code Online (Sandbox Code Playgroud)
可能有问题的一行是这一行:
self.present(textPrompt, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在主照片视图上拍摄屏幕截图时,不会发生警报视图.但是,当设备的方向发生变化时,照片视图会返回列表并显示警报.

iOS 10中的Swift 3
谢谢!
这是列表视图和照片视图的代码:
import UIKit
import Kingfisher
import SKPhotoBrowser
class ListViewCell: UITableViewCell {
@IBOutlet weak var Cellimage: UIImageView!
@IBOutlet weak var cellVenue: UILabel!
@IBOutlet weak var cellLocation: UILabel!
@IBOutlet weak var cellDate: UILabel!
@IBOutlet weak var aiView: UIActivityIndicatorView!
}
class ListViewController: UITableViewController {
var subcategory:Subcategory!
var objects:[[String:String]] = …Run Code Online (Sandbox Code Playgroud) 我需要在警报中添加一个复选框,询问是否应该再次显示此消息.我遇到了各种示例,其中在控制器中添加了按钮或文本字段,但没有在任何地方看到复选框.UIAlertView在版本9之上已被弃用,因此我不想使用它.
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:@"Should I remind?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[self goToAddReminderView];
}];
UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
[self.navigationController popViewControllerAnimated:YES];
}];
[alert addAction:yesAction];
[alert addAction:noAction];
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
我会举一个例子.
ios ×9
swift ×5
objective-c ×4
uialertview ×3
action ×1
checkbox ×1
ios8 ×1
keyboard ×1
swift2 ×1
touch-id ×1
uitextfield ×1