标签: uialertcontroller

UIAlertController抛出NSInvalidArgumentException

我正在尝试使用UIAlertController弹出警报,但我一直收到此错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <States: 0x17557b90>.'

if([InAppPurchaseVerifier hasSubscription]){

    NSUInteger row = [indexPath row];
    NSDictionary *myDict = [[NSDictionary alloc] initWithDictionary:[self.fullList objectAtIndex:row]];

    NSString *state = [[NSString alloc] initWithString: [myDict objectForKey:@"0"]];
    NSString *stateDetails = [[NSString alloc] initWithString: [myDict objectForKey:@"1"]];

    OfficeInfo *anotherViewController = [[OfficeInfo alloc] initWithNibName:@"OfficeInfo" bundle:nil];
    anotherViewController.stateName = state;
    anotherViewController.stateDetails = stateDetails;

    [state release];
    [stateDetails release];

    [self.navigationController pushViewController:anotherViewController animated:YES];
    [anotherViewController release];
}else{
    UIAlertController* alert = [[UIAlertController …
Run Code Online (Sandbox Code Playgroud)

ios uialertcontroller

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

无法为扩展方法UIAlertController提供参数值

我正在尝试编写一个扩展方法,根据您作为参数提供的内容生成UIAlertController.

extension UIAlertController {
   func generate(messageText: String, messageTitle: String, buttonText: String) {
       let alert = UIAlertController(title: messageTitle, message: messageText, preferredStyle: UIAlertControllerStyle.Alert)
       alert.addAction(UIAlertAction(title: buttonText, style: UIAlertActionStyle.Default, handler: nil))
       self.presentViewController(alert, animated: true, completion: nil)
   }
}
Run Code Online (Sandbox Code Playgroud)

这不会给出错误.

但是当我尝试调用它并添加参数值时

var alertTest = UIAlertController.generate("")
Run Code Online (Sandbox Code Playgroud)

它给出以下错误: Type 'UIAlertController' does not conform to protocol 'StringLiteralConvertible'

我怎样才能解决这个问题?

或者我不想实现什么?

swift uialertcontroller

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

如何从类内部调用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
查看次数

如何从任何NSObject子类显示UIAlertController?

我有一个我正在管理的遗留代码库,它需要显示来自各地的警报消息.这是一种可怕的做法,需要一个重构,但这不会很快发生.使用iOS 9,我需要能够触发并忘记警报视图,并为我管理视图显示和排队.

uialertview ios uialertcontroller ios9

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

如何在swift ios中创建自定义UIAlertController?

我正在尝试使UIAlertController看起来像这样:

提醒截图

我们如何定制UIAlertController以获得与此图片相同的结果?

ios swift uialertcontroller

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

如何在app delegate(obj-c)中添加UIAlertController

这是我在弃用UIAlertView之前使用的代码:

//OLD UIALERTVIEW
- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    // check to see if newer version exists to alert the user
    BOOL updateAvailable = NO;
    NSDictionary *updateDictionary = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"PLIST_URL_HERE"]];
    NSArray *items = [updateDictionary objectForKey:@"items"];
    NSDictionary *itemDict = [items lastObject];
    NSDictionary *metaData = [itemDict objectForKey:@"metadata"];
    NSString *newversion = [metaData  valueForKey:@"bundle-version"];
    NSString *currentversion …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uialertcontroller

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

UIalertcontroller序列的按钮

我想更改警报操作按钮的顺序,根据代码,我尝试了所有可能性,但不允许我更改序列.

根据HIG,取消在右侧 https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Alerts.html#//apple_ref/doc/uid/TP40006556-CH14-SW1

在这里查看我的代码

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"alert" message:@"My alert message" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* noButton = [UIAlertAction
                               actionWithTitle:@"Cancel"
                               style:UIAlertActionStyleCancel
                               handler:^(UIAlertAction * action)
                               {
                                   [alertController dismissViewControllerAnimated:YES completion:nil];
                               }];

UIAlertAction* yesButton = [UIAlertAction
                                actionWithTitle:@"OK"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction * action)
                                {

                                    [alertController dismissViewControllerAnimated:YES completion:nil];

                                }];


[alertController addAction:yesButton];
[alertController addAction:noButton];
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

这会给我以下结果.我想在右手边更改取消,button在左手边更改确定button.

在此输入图像描述

我很感激你的时间.

ios uialertcontroller

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

关闭UIAlertController后执行segue

在过去,我曾经遇到过类似的问题,即UIAlertControllerUIAlertController取消后,UI线程上总是存在滞后。
我现在的问题是,如果用户单击“确定”,我想执行顺序检查,如果按下UIAlertAction“取消”,UIAlertAction则什么也不会发生。
这是我的代码:

// create the uialertcontroller to display
let alert = UIAlertController(title: "Do you need help?",
                              message: "Would you like to look for a consultant?",
                              preferredStyle: .alert)
// add buttons
let okay = UIAlertAction(title: "Yes, please.", style: .default, handler: {_ in
    self.performSegue(withIdentifier: "segue", sender: nil)
})
let no = UIAlertAction(title: "No, I'm okay.", style: .cancel, handler: nil)
alert.addAction(okay)
alert.addAction(no)
self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

当前正在发生的是,当我点击“确定”时,segue正在执行,但是我只能看到过渡的最后时刻(即,动画在UIAlertController被关闭时开始播放)。
一旦UIAlertController解散,我如何使segue开始?

注意-如果有其他方法,我宁愿不要以骇人的方式解决此问题,例如在固定的延迟后执行segue。 …

segue swift uialertcontroller

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

如何从UIAlertController中删除延迟?

点击表格单元格后,我将显示4到5秒的延迟,以显示警报视图.下面是代码

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

let cell = tableView.cellForRow(at: indexPath)!
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .alert)

let ok = UIAlertAction(title: "Ok", style: .default, handler: { (action) -> Void in
    let cell = tableView.cellForRow(at: indexPath)!
    })
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) -> Void in
})
   alertController.addAction(ok)
   alertController.addAction(cancel)

present(alertController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

如何避免这种延迟?

uitableview ios swift uialertcontroller

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

UIAlertController消息被截断为一行

在我的应用程序中,在呈现UIAlertController它时将消息截断为一行.如何使用自动换行显示全文显示.

截图

这是我的代码

let alert = UIAlertController(title: title, message:"Long text"  , 
preferredStyle: UIAlertControllerStyle.alert) 

let okAction = UIAlertAction(title: "OK", style: 
UIAlertActionStyle.default, handler: nil)  

alert.addAction(okAction)

self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

user-interface swift uialertcontroller

2
推荐指数
3
解决办法
2567
查看次数