标签: uialertcontroller

如何在UIAlertController中添加textField?

在此输入图像描述

在此输入图像描述

我想实现一个关于更改密码的功能,它需要用户输入他以前的密码,我在一个警告对话框中设计它,我想点击"确认修改"按钮,然后跳转到另一个视图控制器更改密码.我写了一些代码,但我不知道下一刻该如何写.

objective-c uitextfield ios uialertcontroller

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

如何在UIAlertController外部点击时关闭UIAlertController?

如何UIAlertController在外面敲击时解雇UIAlertController

我可以添加一种UIAlertAction风格UIAlertActionStyleCancel来解雇UIAlertController.

但我想补充一点,当外界使用者开关功能UIAlertControllerUIAlertController将开除.怎么做?谢谢.

uialertview ios uialertcontroller

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

在UIAlertAction的处理程序中,自我应该被捕获为强者吗?

当写一个handler关闭的时候UIAlertAction,应该引用self强(默认)weak,还是unowned

已经有相关与这个主题(帖子1,2,3,4),但老实说,我不认为他们在这种情况下如何帮助.

让我们关注这个典型的代码:

func tappedQuitButton() {
    let alert = UIAlertController(title: "Confirm quit", message: nil, preferredStyle: .ActionSheet)

    let quitAction = UIAlertAction(title: "Quit", style: .Default) { (action) in
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    alert.addAction(quitAction)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    alert.addAction(cancelAction)

    presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

这是UIViewController子类内部的一个函数,self视图控制器也会显示警报.

文件说:

只要该引用可能在其生命中的某个点上具有"无值",就使用弱引用来避免引用循环.如果引用始终具有值,请改用无主引用.

我可能会失明,但我仍然没有看到这有助于回答我的问题 …

ios swift uialertcontroller uialertaction

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

UIAlertController - 向操作表添加自定义视图

当我们尝试在屏幕截图中附加图像时,我正在尝试制作在iOS上的消息应用中显示的操作表.

我意识到在新的UIAlertController中,我们无法适应任何自定义视图.我有什么方法可以做到这一点?

我的代码看起来很标准.

    let alertController = UIAlertController(title: "My AlertController", message: "tryna show some images here man", preferredStyle: UIAlertControllerStyle.ActionSheet)

        let okAction = UIAlertAction(title: "oks", style: .Default) { (action: UIAlertAction) -> Void in
        alertController.dismissViewControllerAnimated(true, completion: nil)
    }
    let cancelAction = UIAlertAction(title: "Screw it!", style: .Cancel) { (action: UIAlertAction) -> Void in
        alertController.dismissViewControllerAnimated(true, completion: nil)
    }

    alertController.addAction(okAction)
    alertController.addAction(cancelAction)

    self.presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

swift uialertcontroller ios9

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

AlertController不在窗口层次结构中

我刚刚用ViewController类创建了一个单视图应用程序项目.我想从一个位于我自己的类中的函数中显示一个UIAlertController.

这是我的班级提醒.

class AlertController: UIViewController {
     func showAlert() { 
         var alert = UIAlertController(title: "abc", message: "def", preferredStyle: .Alert)
         self.presentViewController(alert, animated: true, completion: nil)
     }
}
Run Code Online (Sandbox Code Playgroud)

这是执行警报的ViewController.

class ViewController: UIViewController {
   override func viewDidLoad() {
       super.viewDidLoad()  
   }

   @IBAction func showAlertButton(sender: AnyObject) {
       var alert = AlertController()
       alert.showAlert()
   }
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的,而不是美丽的警报.

警告:尝试在Sprint1.AlertController上显示UIAlertController:0x797d2d20:0x797cc500,其视图不在窗口层次结构中!

我该怎么办?

storyboard uialertview ios swift uialertcontroller

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

UIAlertController文本对齐

有没有办法更改iOS 8上UIAlertController内显示的消息的对齐方式?

我相信不再可能访问子视图并为UILabel更改它.

ios ios8 uialertcontroller

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

UIAlertController显示延迟

我在我的应用程序上遇到UIAlertController的问题,现在已经迁移到带有日期选择器的iOS8.

下面是代码.

UIAlertController *AlertView = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];

 UIAlertAction *ok = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
[AlertView dismissViewControllerAnimated:YES completion:nil];
}];

 UIAlertAction *set = [UIAlertAction actionWithTitle:NSLocalizedString(@"Set to today", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
[self set_to_today:nil];
[AlertView dismissViewControllerAnimated:YES completion:nil];
[self.tableView reloadData];
}];

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


 UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
 datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker setDate:data_appo];
[datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];

[AlertView.view addSubview:datePicker];
[AlertView addAction:ok];
[AlertView addAction:set];
[AlertView addAction:cancel];
[self.view …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uialertview swift uialertcontroller

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

UIAlertController:supportedInterfaceOrientations是递归调用的

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

请帮助我.

objective-c uialertcontroller ios9 xcode7 xcode7-beta3

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

当调用`presentViewController:`时,UIAlertController被移动到屏幕顶部的错误位置

从一个视图呈现视图UIAlertController将警报移动到屏幕左上角的一个有缺陷的位置.iOS 8.1,设备和模拟器.

当我们尝试从当前"最顶层"视图中呈现视图时,我们在应用程序中注意到了这一点.如果UIAlertController恰好是最顶层的视图,我们会得到这种行为.我们已经更改了我们的代码以简单地忽略UIAlertControllers,但我发布这个以防其他人遇到同样的问题(因为我找不到任何东西).

我们已将此分离为一个简单的测试项目,该问题底部的完整代码.

  1. viewDidAppear:在新的Single View Xcode项目中实现View Controller.
  2. 提出UIAlertController警报.
  3. 警报控制器立即调用presentViewController:animated:completion:显示然后关闭另一个视图控制器:

presentViewController:...动画开始的那一刻,UIAlertController被移动到屏幕的左上角:

警报已移至屏幕顶部

dismissViewControllerAnimated:动画结束,警报已被移动甚至进一步进入屏幕的左上角边距:

警报已移至屏幕的左上边缘

完整代码:

- (void)viewDidAppear:(BOOL)animated {
    // Display a UIAlertController alert
    NSString *message = @"This UIAlertController will be moved to the top of the screen if it calls `presentViewController:`";
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"UIAlertController iOS 8.1" message:message preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"I think that's a Bug" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];

    // The UIAlertController should Present and then Dismiss a …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uialertview ios ios8 uialertcontroller

37
推荐指数
5
解决办法
9758
查看次数

从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万
查看次数