相关疑难解决方法(0)

获得最顶级的UIViewController

如果UIViewController没有访问权限,我似乎无法获得最高分UINavigationController.这是我到目前为止:

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

但是,它似乎没有做任何事情.在keyWindowrootViewController似乎是非零值太多,所以可选的链接不应该是一个问题.

注意: 做这样的事情是个坏主意.它打破了MVC模式.

uiviewcontroller swift

174
推荐指数
14
解决办法
12万
查看次数

检查UIAlertController是否已经呈现的最佳方法是什么?

我有一个tableview,当加载时,每个单元格可能会返回一个NSError,我已经选择在UIAlertController中显示它.问题是如果返回多个错误,我会在控制台中收到此错误.

警告:尝试在MessagesMasterVC上呈现UIAlertController:0x14e64cb00:0x14e53d800已经呈现(null)

理想情况下,我希望在我的UIAlertController扩展方法中处理这个问题.

class func simpleAlertWithMessage(message: String!) -> UIAlertController {

    let alertController = UIAlertController(title: nil, message: message, preferredStyle: UIAlertControllerStyle.Alert)
    let cancel = UIAlertAction(title: "Ok", style: .Cancel, handler: nil)

    alertController.addAction(cancel)
    return alertController
}
Run Code Online (Sandbox Code Playgroud)

基于matt的答案,我将扩展名更改为UIViewController扩展,更加清晰,并节省了大量的presentViewController代码.

    func showSimpleAlertWithMessage(message: String!) {

    let alertController = UIAlertController(title: nil, message: message, preferredStyle: UIAlertControllerStyle.Alert)
    let cancel = UIAlertAction(title: "Ok", style: .Cancel, handler: nil)

    alertController.addAction(cancel)

    if self.presentedViewController == nil {
        self.presentViewController(alertController, animated: true, completion: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

ios uialertcontroller

101
推荐指数
5
解决办法
5万
查看次数

我可以检查现在是否有任何UIAlertView显示?

我可以在iOS应用程序的任何部分检查是否有任何UIAlertView现在显示?我找到了这段代码

[NSClassFromString(@"_UIAlertManager") performSelector:@selector(topMostAlert)]
Run Code Online (Sandbox Code Playgroud)

但它是私有API,我的应用程序可能会被Apple拒绝.有没有合法的方法来做到这一点?

iphone objective-c ipad ios

6
推荐指数
1
解决办法
7931
查看次数