如何UIAlertController在外面敲击时解雇UIAlertController?
我可以添加一种UIAlertAction风格UIAlertActionStyleCancel来解雇UIAlertController.
但我想补充一点,当外界使用者开关功能UIAlertController的UIAlertController将开除.怎么做?谢谢.
当写一个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上的消息应用中显示的操作表.
我意识到在新的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)
我刚刚用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,其视图不在窗口层次结构中!
我该怎么办?
有没有办法更改iOS 8上UIAlertController内显示的消息的对齐方式?
我相信不再可能访问子视图并为UILabel更改它.
我在我的应用程序上遇到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) 当两个警报一个接一个地呈现时,我意味着一个警报存在,并且在他们上面另一个警报呈现和应用程序崩溃.我曾经用来UIAlertController显示警报.应用程序仅在iOS 9设备中崩溃.
请帮助我.
从一个视图呈现视图UIAlertController将警报移动到屏幕左上角的一个有缺陷的位置.iOS 8.1,设备和模拟器.
当我们尝试从当前"最顶层"视图中呈现视图时,我们在应用程序中注意到了这一点.如果UIAlertController恰好是最顶层的视图,我们会得到这种行为.我们已经更改了我们的代码以简单地忽略UIAlertControllers,但我发布这个以防其他人遇到同样的问题(因为我找不到任何东西).
我们已将此分离为一个简单的测试项目,该问题底部的完整代码.
viewDidAppear:在新的Single View Xcode项目中实现View Controller.UIAlertController警报.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) 我正试图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)
导致错误的原因是什么?如何解决?
ios ×7
objective-c ×4
swift ×4
uialertview ×4
ios8 ×2
ios9 ×2
appdelegate ×1
cocoa-touch ×1
storyboard ×1
uitextfield ×1
xcode ×1
xcode7 ×1
xcode7-beta3 ×1