标签: uialertcontroller

self.navigationController?来自UIAlertController的.popViewControllerAnimated

我是新手,但我想我已经掌握了它.这让我的进步很难过.

我想要做的是当我们无法找到他的查询的相关数据时向用户抛出错误消息,然后继续将他带回到之前的ViewController.

但是,我在这方面遇到了麻烦.在我添加操作的行上,我收到以下错误:'UIViewController?' 不是Void的子类型

let alertController = UIAlertController(title: "Oops", message: "We couldn't find any data for this title, sorry!", preferredStyle: UIAlertControllerStyle.Alert)

alertController.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in
    self.navigationController?.popViewControllerAnimated(true)   
}))
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?我错过了一些明显的东西吗 我试着搞砸了被弃用的UIAlertView,但却没有变得更聪明.

xcode uinavigationcontroller ios swift uialertcontroller

7
推荐指数
1
解决办法
3986
查看次数

UIAlertController'UIAlertAction'标签/用户数据或Swift中的任何内容

在我的iOS动作表中,我显示了JSON字典中的Names:

[
  { "Name": "Doctor for Disease AAA",
    "Doctor_id": "21"
  },
  { "Name": "Doctor for Disease BBB",
    "Doctor_id": "22"
  },
  { "Name": "Doctor for Disease AAA",
    "Doctor_id": "25"
  }
]
Run Code Online (Sandbox Code Playgroud)

因此,在按钮单击委托时,我可以获取按钮索引并可以获取相应的"名称"和"Doctor_id".这工作正常.

但现在好像'UIActionSheet'已被弃用,我必须使用'UIAlertController'.因为我有一个大数据,我正在遍历我的数组值并调用alertcontroller处理程序(所以单击所有按钮的单个函数).但是如何从UIAlertController获取按钮索引,以便我可以同时获取"Name"和"Doctor_id".

请帮我.

ios swift uialertcontroller

7
推荐指数
3
解决办法
6268
查看次数

UIAlertController圆角矩形文本字段

我在为我设置文本字段时遇到一些问题UIAlertController.

我正在使用此代码添加舍入textfieldalertcontroller:

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

谢谢!

uitextfield uialertview ios uialertcontroller

7
推荐指数
1
解决办法
797
查看次数

UIAlertController中的多行可编辑文本UITextview?

如何UITextview在一个内部制作多行可编辑文本UIAlertControllerUITextfield支持单行,我们需要在弹出窗口中创建一个多行文本编辑框.

ios swift uialertcontroller swift2

7
推荐指数
3
解决办法
9327
查看次数

自定义动作控制器,Swift

有谁知道我如何编写这个自定义警报控制器(特别是顶部区域) - 目前在Apple音乐应用程序上找到.也许有一个已知的库可以做到这一点.

我知道你是如何对动作控制器进行编码的?

let alertController = UIAlertController(title: nil, message: "Top Message Here", preferredStyle: .ActionSheet)


        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
            // Drop View Pop up

        }

        alertController.addAction(cancelAction)

        let action1 = UIAlertAction(title: "Action Title", style: .Default) { (action) in

            //Code to Execute

        }

        alertController.addAction(action1)
        self.presentViewController(alertController, animated: true) {
            // ...

        }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ios swift uialertcontroller

7
推荐指数
1
解决办法
1万
查看次数

如何处理UIAlertController的操作?

如何使用objective-c将UIAlertController警报操作按钮与操作处理程序链接?我正在使用Xcode 7.1.

这是我的代码:

- (IBAction)selectbtn:(UIButton *)sender {

    UIAlertController *alert=[ UIAlertController alertControllerWithTitle:@"NEW" message:@"button pressed" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cameraaction=[UIAlertAction actionWithTitle:@"From camera" style:UIAlertActionStyleDefault handler:nil ];
    [alert addAction:cameraaction];
    UIAlertAction *libraryaction=[UIAlertAction actionWithTitle:@"From photo library" style:UIAlertActionStyleDefault handler:nil ];
    [alert addAction:libraryaction];
    UIAlertAction *cancelaction=[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDestructive handler:nil];
    [alert addAction:cancelaction];
    [self presentViewController:alert animated:YES
                     completion:nil];
    }
Run Code Online (Sandbox Code Playgroud)

objective-c ios uialertcontroller

7
推荐指数
2
解决办法
2万
查看次数

如何在Swift中显示一条弹出消息,该消息在3秒后消失或者可以被用户立即取消?

在我的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)

这很好,但我想介绍一些改进.我想添加一个按钮,立即取消此弹出窗口,然后避免在控制台中显示该消息.有没有办法向用户显示这样的弹出窗口?另外 - 有没有一种方法可以在这个弹出消息中显示计数器的秒数,这个计数器显示弹出消失之前还剩多少时间?

uialertview ios swift uialertcontroller

7
推荐指数
1
解决办法
1万
查看次数

Swift Custom UIAlertView

我正在尝试进行确认删除弹出视图.因为我想要的设计与典型UIAlertView弹出窗口的风格截然不同,所以我决定创建一个ConfirmationViewController我会触发弹出的自定义.

这是典型的UIAlertView外观:

在此输入图像描述

这就是我想要的样子:

在此输入图像描述

这是我目前正在制作自定义ConfirmationViewController弹出窗口的方式:

let confirmationViewController = ConfirmationViewController()
confirmationViewController.delegate = self
confirmationViewController.setTitleLabel("Are you sure you want to remove \(firstName)?")
confirmationViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
confirmationViewController.preferredContentSize = CGSizeMake(230, 130)

let popoverConfirmationViewController = confirmationViewController.popoverPresentationController
popoverConfirmationViewController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
popoverConfirmationViewController?.delegate = self
popoverConfirmationViewController?.sourceView = self.view
popoverConfirmationViewController?.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
presentViewController(
    confirmationViewController,
    animated: true,
    completion: nil)
Run Code Online (Sandbox Code Playgroud)

以下是按下CANCELREMOVE按钮时我收到通知的方式:

extension UserProfileTableViewController: ConfirmationViewControllerDelegate {
    func cancelButtonPressed() {
        print("Cancel button pressed")
    }

    func confirmationButtonPressed(objectToDelete: AnyObject?) {
        print("Delete button …
Run Code Online (Sandbox Code Playgroud)

uialertview ios completionhandler swift uialertcontroller

7
推荐指数
1
解决办法
9160
查看次数

如何在Swift中旋转UIAlertController

我有一个工作UIAlertController,但我想alert.view向左旋转90度.

我该怎么做?我的代码如下:

let alert = UIAlertController(title: "", message: "Message Sample", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Okay", style: .Default){(action)->() in })
presentViewController(alert, animated: true) {}
Run Code Online (Sandbox Code Playgroud)

我试着添加:

 alert.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

谢谢 !

uialertview ios swift uialertcontroller swift3

7
推荐指数
1
解决办法
1252
查看次数

自iOS 13起,每个UIAlertController都会在用户响应之前自动消失

由于我使用的是iOS 13,因此我的每个UIAlertController都会显示大约半秒钟,并且在用户执行任何操作之前会立即消失。任何的想法 ?

当我从应用程序的不同部分使用UIAlertController时,我使用了一个扩展,该扩展允许我同时从经典视图和collectionView(单元格,标头等)弹出。

public extension UIAlertController {
    func show() {
        let win = UIWindow(frame: UIScreen.main.bounds)
        let vc = UIViewController()
        vc.view.backgroundColor = .clear
        vc.view.tintColor = Theme.mainAccentColor
        win.rootViewController = vc
        win.windowLevel = UIWindow.Level.alert + 1
        win.makeKeyAndVisible()
        vc.present(self, animated: true, completion: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是此扩展名用法的示例:

fileprivate func showMissingAlert() {
        let alert = UIAlertController(title: "blablabla", message: "blablablablabla blabla", preferredStyle: UIAlertController.Style.alert)
        alert.show()
        alert.view.tintColor = Theme.mainAccentColor
        let cancelAction = UIAlertAction(title: "OK, blabla", style: .default, handler: {(alert: UIAlertAction!) in print("ok, leave")})
        alert.addAction(cancelAction)
    }
Run Code Online (Sandbox Code Playgroud)

进一步在我的代码中:

showMissingAlert()
Run Code Online (Sandbox Code Playgroud)

在iOS …

swift uialertcontroller ios13

7
推荐指数
1
解决办法
651
查看次数