标签: uialertcontroller

从UITableViewCell上的按钮显示UIAlertController

这是我在一个按钮内编码的内容UITableViewCell.

var shareAlert = UIAlertController(title: "Post Alert", 
    message: "Your Post has been Shared with your Friends", 
    preferredStyle: UIAlertControllerStyle.Alert)

var Ok = UIAlertAction(title: "Ok", 
    style: UIAlertActionStyle.Default, 
    handler: nil)

shareAlert.addAction(Ok)
shareAlert.presentViewController(shareAlert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

当用户单击按钮时,我希望它显示此警报,但是一旦我单击按钮,应用程序就会崩溃.我做错了吗?如何从按钮中显示警报视图UITableViewCell

uitableview ios swift uialertcontroller

2
推荐指数
1
解决办法
1788
查看次数

XCode 7 UI测试:解除系统生成的UIAlertController不起作用

我有一个UI测试,涉及解雇系统生成UIAlertController.此警报要求用户访问设备日历的权限.测试的目标是点击OK按钮后的行为:

1 let app = XCUIApplication()
...
// this code was basically generated by the recording feature of XCode 7 
2 app.alerts.elementBoundByIndex(0).collectionViews.buttons["OK"].tap()
Run Code Online (Sandbox Code Playgroud)

现在,OK第2行不是点击按钮,而是让模拟器点击第一个按钮,该Cancel按钮恰好是按钮......

此外,我发现测试框架无法准确识别出现的警报.因此,如果我检查当前的警报计数,我总是得到0:

// ...tap...
let count = app.alerts.count // == 0
Run Code Online (Sandbox Code Playgroud)

如果我使用NSPredicate条件并等待几秒钟,也会发生这种情况.

UI测试是否可能无法与系统生成的警报一起可靠地工作?我正在使用XCode 7.0.1.

ui-testing uialertcontroller xcode7 xcode-ui-testing

2
推荐指数
1
解决办法
1772
查看次数

iOS 9.0 - 从UIAlertController操作表中删除顶部栏

在创建一个动作表时UIAlertController,我看到一个顶部栏总是显示.这篇SO帖子建议将标题设置为nil- 这可能适用于iOS 8.0,但我在iOS 9.0上看到了一个顶级栏.

在此输入图像描述

ios uialertcontroller ios9

2
推荐指数
1
解决办法
1097
查看次数

在GameScene中显示UIAlertController(SpriteKit/Swift)

在swift中显示UIAlertView的简单方法是:

let alert = UIAlertView()
alert.title = "Alert!"
alert.message = "A wise message"
alert.addButtonWithTitle("Ok, thank you")
alert.show()
Run Code Online (Sandbox Code Playgroud)

但现在这在iOS 9中已经过折旧,建议使用UIAlertController:

let myAlert: UIAlertController = UIAlertController(title: "Alert!", message: "Oh! Fancy", preferredStyle: .Alert)
myAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(myAlert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

哪个好,但我在使用SpriteKit并在GameScene中,这给出了一个错误Value of type 'GameScene' has no member 'presentViewController'...

我是否需要切换回我的ViewController来呈现这个或者有没有办法从GameScene中调用它.

我找到了这个答案,但它是Objective-C.

uialertview ios sprite-kit swift uialertcontroller

2
推荐指数
1
解决办法
3614
查看次数

如何在警报中从TextField获取输入文本

之前已经问过这个问题:在Swift的iOS警报中从TextField获取输入值.但是,有人拥有Objective-C语言的代码吗?

提前致谢!

到目前为止我得到了什么:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Adding A Row"
    message:@"Enter A Number"
    preferredStyle:UIAlertControllerStyleAlert];

[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"";
}];

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    [alert dismissViewControllerAnimated:YES completion:nil];
}];

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//Do some action here
}];

[alert addAction:cancel];
[alert addAction:ok];

[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

objective-c ios uialertcontroller

2
推荐指数
1
解决办法
2943
查看次数

UIAlert控制器上的图标

有没有人知道如何在UI警报控制器中添加图标的方式与页面应用程序所附的方式相同,如下图所示.

提前致谢.:)

在此输入图像描述

ios swift uialertcontroller

2
推荐指数
1
解决办法
966
查看次数

如何创建可重用的UIAlertcontroller?

我想为我的项目创建一个可重用的UIAlertController类.我尝试了以下代码.但我的警报没有显示.我的代码或任何代码帮助有什么问题.这是我的警报类

class AlertView: NSObject {

 class func showAlert(view: UIViewController , message: String){

        let alert = UIAlertController(title: "Warning", message: message, preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        view.presentViewController(alert, animated: true, completion: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

我在另一个视图控制器中调用它

class ViewController: UIViewController {

  override func viewDidLoad() {
      super.viewDidLoad()
      AlertView.showAlert(self, message: "Test alert")
      // Do any additional setup after loading the view, typically from a nib.
   }
}
Run Code Online (Sandbox Code Playgroud)

iphone ios swift uialertcontroller

2
推荐指数
1
解决办法
2518
查看次数

如何在alertcontroller存在时模糊viewcontroller?

是否有可能做到这一点 ??我有一个出现在viewcontroller中的UIAlertController.我希望实现的是当警报出现时模糊/覆盖背景,一旦警报消失,背景应该是可见的

import UIKit import LocalAuthentication类TabBarViewController:UITabBarController {

@IBOutlet weak var noteTabBar: UITabBar!

override func viewDidLoad() {
super.viewDidLoad()
    self.authenticateUser()
    self.tabBar.hidden = false
    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

    let userDefaults = NSUserDefaults.standardUserDefaults()
    userDefaults.setObject(false, forKey: "sendModeToggle")
    userDefaults.setObject("Avenir-Medium", forKey: "font")
     userDefaults.setObject(13, forKey:"fontSize")
            // Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation …
Run Code Online (Sandbox Code Playgroud)

swift uialertcontroller

2
推荐指数
1
解决办法
3973
查看次数

在UITableView中发出警报的奇怪延迟

我有一些UITableView来自内部的数据array.我想UIAlertController点击显示,但我遇到了非常奇怪的延迟.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    print("tapped \(dispatcher.conversations[indexPath.row].name)") //this one works fine, no problems here

    let message = dispatcher.conversations[indexPath.row].desc + "\n\nDo you wanna play this?"
    let alertname = dispatcher.conversations[indexPath.row].name

    let alert = UIAlertController(title: alertname, message: message, preferredStyle: .alert)

    let actionOK = UIAlertAction(title: "Play", style: UIAlertActionStyle.default, handler: { (action) in
        //play the file
    })

    let actionCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (action) in
        //cancel the file
    })

    alert.addAction(actionOK)
    alert.addAction(actionCancel)

    self.present(alert, …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uialertcontroller

2
推荐指数
1
解决办法
525
查看次数

Xcode Swift如何将图像添加到UIAlertController选项?

我想添加图像/图标来UIAlertController喜欢苹果音乐播放器中的对话框

我想要的是彩色/大尺寸图像/图标,如下面的图像,而不是这个问题中的一个。我相信它的ios 11+功能,但是我找不到它的文档。

完全像这样:

在此处输入图片说明

我可以这样做UIAlertController还是应该创建自己的自定义对话框uiviewcontroller

xcode swift uialertcontroller

2
推荐指数
1
解决办法
2372
查看次数