相关疑难解决方法(0)

UIAlertController:supportedInterfaceOrientations是递归调用的

当两个警报一个接一个地呈现时,我意味着一个警报存在,并且在他们上面另一个警报呈现和应用程序崩溃.我曾经用来UIAlertController显示警报.应用程序仅在iOS 9设备中崩溃.

请帮助我.

objective-c uialertcontroller ios9 xcode7 xcode7-beta3

39
推荐指数
3
解决办法
8407
查看次数

从AppDelegate展示UIAlertController

我正试图UIAlertController在我的iOS应用程序中呈现AppDelegate.以下是警报和本方法.

UIAlertController *alert = [UIAlertController alertControllerWithTitle:cTitle message:cMessage preferredStyle:UIAlertControllerStyleAlert];

//Configure alert and actions

[self.window.rootViewController presentViewController:alert animated:TRUE completion:nil];
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试显示警报时,它不会出现,我在控制台中收到以下警报.

Warning: Attempt to present <UIAlertController: 0x145f5d60> on <UINavigationController: 0x146590f0> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)

导致错误的原因是什么?如何解决?

objective-c ios appdelegate uialertcontroller

34
推荐指数
4
解决办法
3万
查看次数

在键盘上显示UIAlertController

在iOS 8及更低版本中显示UIActionSheet何时呈现键盘将在键盘上显示操作表.对于iOS 9,情况已不再如此.

在我的应用程序中,我们有一个聊天功能,并希望该节目通过键盘进行操作.我们过去常常使用UIActionSheet哪种工作正常,直到iOS 8.在iOS 9中,操作表存在于键盘后面.我都试过UIActionSheetUIAlertController.

我们想要的是一个像messages.app中的动作表 消息应用中的操作表.

我已经尝试将动作表放在它自己的窗口中并覆盖canBecomeFirstResponder,这使得键盘消失了.

keyboard uialertcontroller ios9

16
推荐指数
3
解决办法
7104
查看次数

IOS以编程方式创建UIAlertViewController

我正在使用带有代码的ViewController(没有故事板).我正在尝试添加和AlertController

我已经在.m中声明了

@property (nonatomic, strong) UIAlertController *alertController;
Run Code Online (Sandbox Code Playgroud)

并在loadview方法中初始化

//alertviewController
    _alertController = [[UIAlertController alloc]initWithNibName:nil bundle:nil];
Run Code Online (Sandbox Code Playgroud)

并在viewDidLoad以下位置调用alertview :

_alertController = [UIAlertController alertControllerWithTitle:@"Error display content" message:@"Error connecting to server, no local database" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                LandingPageViewController *viewController = [[LandingPageViewController alloc] initWithNibName:nil bundle:nil];
    //            viewController.showNavBarBackButton = YES;
                [[AppDelegate sharedAppDelegate].rootViewController cPushViewController:viewController];
}];
[_alertController addAction:ok];
[self presentViewController:_alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

我不知道为什么警报没有显示出来.我的代码出了点问题.如何以alertViewController编程方式设置和调用?

objective-c uialertview ios

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

并发UIAlertControllers

我正在将我的应用程序移植到iOS 8.0,并注意到UIAlertView已被弃用.

所以我改变了使用UIAlertController的东西.在大多数情况下都有效.

除了,当我的应用程序打开时,它会进行多次检查以向用户报告各种状态...

例如.."警告,你没有设置X并且在完成项目之前需要做Y"和"警告,你正在使用测试版并且不依赖于结果"等......(这些只是示例!)

在UIAlertView下,我会(比如说)同时获得两个警告框,用户必须点击两次才能解除两个...但它们都出现了.

在UIAlertController下面,使用下面的代码来显示"常规"警报,我只收到一条警报消息以及一条控制台消息:

警告:尝试在TestViewController上呈现UIAlertController:0x13f667bb0:0x13f63cb40已经呈现UIAlertController:0x13f54edf0

所以,虽然上面可能不是一个很好的例子,但我想有时可能需要在操作应用程序时因"事件"而提出多个全局警报.在旧的UIAlertView下,它们会出现,但似乎它们不会在UIAlertController下.

任何人都可以建议如何使用UIAlertController实现这一目标?

谢谢

+(void)presentAlert:(NSString*)alertMessage withTitle:(NSString*)title
{
    UIAlertController *alertView = [UIAlertController
                                    alertControllerWithTitle:title
                                    message:alertMessage
                                    preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:kOkButtonTitle
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             //Do some thing here
                             [alertView dismissViewControllerAnimated:YES completion:nil];
                         }];

    [alertView addAction:ok];

    UIViewController *rootViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
    [rootViewController presentViewController:alertView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

编辑:我注意到在iOS8上,连续呈现两个AlertViews,它们"排队"并按顺序出现,而在iOS7中,它们同时出现.似乎Apple已经改变了UIAlertView来排队多个实例.是否有办法使用UIAlertController执行此操作而不继续使用(已弃用但已修改)UIAlertView ???

uialertview ipad ios8 uialertcontroller

15
推荐指数
1
解决办法
5513
查看次数

将视图添加到窗口层次结构

我正试图在我的游戏上创建一个暂停屏幕.我在故事板中添加了一个'PauseScreen'viewController,故事板ID和Restoration ID设置为"PauseScreenID",并移动到暂停屏幕我已在"GameScene"中创建了该功能:

func pauseSceenTransition(){

    let viewController = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("PauseScreenID") as UIViewController

    let currentViewController = (UIApplication.sharedApplication().delegate as AppDelegate)

    currentViewController.window?.rootViewController?.presentViewController(viewController, animated: false, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

但是当它被调用时,我得到错误:

警告:尝试在< AppName .StartScreenViewController:0x7fae61f79980>上显示< AppName .PauseScreen:0x7fae61fe5ff0>,其视图不在窗口层次结构中!

"StartScreenViewController"是我的开始屏幕的视图控制器,是初始视图控制器.然后转到"GameScene",这是"PauseScreen"需要去的地方.如果我将初始视图控制器设置为"GameViewController"/"GameScene",它可以工作,所以我认为我需要更改第二行:

let currentViewController = (UIApplication.sharedApplication().delegate as AppDelegate)
Run Code Online (Sandbox Code Playgroud)

所以它在"GameViewController"上呈现"PauseScreen",而不是"StartScreenViewController",但我不知道该怎么做.

viewcontroller presentviewcontroller swift xcode6

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

UIAlertController状态栏不会变暗和着色颜色问题

我正在从使用迁移UIAlertViewUIAlertControlleriOS 8中的介绍.但是,我看到一些奇怪的视图问题,我在使用时没有看到UIAlertView.首先,在显示警报时,状态栏文本不会变暗:

状态栏不变暗

此外,在显示状态栏后,UINavigationController现在将后面的箭头设置为应用程序的tintColor,而不是为我设置的白色tintColor UINavigationBar.这会影响UINavigationBar整个应用程序中的其他元素,例如添加(+)按钮和编辑按钮.在显示之前UIAlertController,所有条形按钮项目都显示为白色.

后退按钮的色调错误

错误的色调用于编辑和后退按钮

我在这里不知所措.我显示警报的代码非常简单:

UIAlertController *view = [UIAlertController alertControllerWithTitle:VALIDATION_TITLE message:text preferredStyle:UIAlertControllerStyleAlert];
[view addAction:[UIAlertAction actionWithTitle:VALIDATION_BUTTON_OK style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:view animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios8 uialertcontroller ios9

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

UIAlertController 下最顶层的 ViewController

我正在使用以下扩展来查找最顶层的 ViewController。如果出现警报,上面的代码会给出UIAlertController. 如何在 下 UIAlertController获得顶视图控制器?

uiviewcontroller ios swift uialertcontroller

6
推荐指数
2
解决办法
4132
查看次数

如何从类内部调用presentViewController

在我的完成处理程序中,我试图像alertJS 一样返回http响应代码.一旦我得到这个排序,我希望改进我的if语句,以确定最终用户的连接问题.我在看这篇文章.

http://www.ioscreator.com/tutorials/display-an-alert-view-in-ios8-with-swift

我也看到这个回答Simple App Delegate方法来显示一个UIAlertController(在Swift中),但是我得到了一个关于window未被命名的类似方法.

没有所有噪音的代码是这样的:

class NewsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

var tableView: UITableView!
var titleItems: NSMutableArray = []
var descritpionItems: NSMutableArray = []

class RemoteAPI {

    // base url
    let baseUrl = "http://api.dev/web/"
    // returned array of news titles + descriptions
    var newsTitle: NSMutableArray = []
    var newsDescription: NSMutableArray = []

    func getData(completionHandler: ((NSArray?, NSError?) -> Void)) -> Void {
        // get news feed url
        let url = NSURL(string: baseUrl + …
Run Code Online (Sandbox Code Playgroud)

swift uialertcontroller

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

使用UIWindow()进行单元测试时,NSInternalConsistencyException

我一直在使用以下帖子作为如何显示UIAlertController与特定无关的from代码的指导UIViewController。现在,我要对该代码进行单元测试:

func showAlert(alert: UIAlertController, animated: Bool, completion: (()->Void)?) 
{
    let alertWindow = UIWindow(frame: UIScreen.mainScreen().bounds)

    // Keep a strong refence to the window. 
    // We manually set this to nil when the alert is dismissed
    self.alertWindow = alertWindow

    alertWindow.rootViewController = UIViewController()        
    if let currentTopWindow = UIApplication.sharedApplication().windows.last {
        alertWindow.windowLevel = currentTopWindow.windowLevel + 1
    }
    else {
        // This case only happens during unit testing
        Logger.trace(ICELogLevel.Error, category: .Utility, message: "The application doesn't have a window being displayed!") …
Run Code Online (Sandbox Code Playgroud)

unit-testing uiwindow ios swift uialertcontroller

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

你如何从子视图提出ViewController?

假设我们有一个自定义控件,在某些状态下应弹出选项列表供用户选择(UIAlertController).通常当我们在视图控制器中时,我们使用presentViewController方法,但在这种情况下,我们无法访问保存此方法的父UIViewController.虽然似乎有一些方法可以从子视图中获取UIViewController,但它被认为是针对MVC设计模式的.那你怎么这样做?我想保持视图控制器尽可能精简,自定义视图(uicontrol)自给自足,所以我不想将此逻辑移动到视图控制器.虽然欢迎并赞赏您的所有建议和建议.

uiviewcontroller ios presentviewcontroller swift uialertcontroller

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