如何在swift中为警报视图设置标记.我无法设置标签alert.tag = 1,如果我这样做,我会收到类似的错误'UIAlertController' does not have a member named 'tag'.以下是我写的代码,
var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "YES", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in }))
alert.addAction(UIAlertAction(title: "NO", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in }))
alert.tag = 1 // Error is shown here
self.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我们曾经在Obj-C中为警报视图设置标签.有人可以帮我这个.提前致谢.
在自定义视图中直到iOS7,我们可以将tableview置于警报状态,如下图所示.
但是在iOS8中,UITableview无法正常工作.我可以把它放在tableview中,但tableview不滚动,也没有检测到任何单元格上的任何点击.
那么,我该如何实现这种类型的AlertController呢?
在我的Swift应用程序中,我检查了locationServiceEnabled().如果它返回false,我应该使用UIAlertController提示用户进行位置设置.可以这样做吗?我使用此函数来提示应用程序的位置设置:
func displayAlertToEnableLocationServicesApp()
{
let alertController = UIAlertController(
title: "Location Access is Turned Off",
message: "In order to locate your position, please open settings and set location access to 'While Using the App'",
preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
let openAction = UIAlertAction(title: "Settings", style: .Default) { (action) in
if let url = NSURL(string: UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(url)
}
}
alertController.addAction(openAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
但是这个功能打开设置应用程序,而不是位置设置.我需要打开(设置 - >隐私 - >位置)
谢谢
我知道如何通过使用喜欢添加任何Custom UI内部UIAlertView,但我现在好奇,如果我们仍然有选择添加内部,我想要有一个内部清楚的理解.accessoryViewUITableViewCustom UIUIAlertControllerUITableViewControllerUIAlertController
是否可以制作UIAlertController方形角而不是默认的圆角?
(我知道可以使用第三方库,但我想知道如何使用苹果UIAlertController.)
我创建两个按钮UIAlertcontroller:
One Button - "OpenCamera"
Two button - "OpenGallery"
Run Code Online (Sandbox Code Playgroud)
当我点击其中一个时,我无法理解我是如何创建动作的.
- (IBAction)takePic:(id)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet]; // 1
UIAlertAction *openCamrea = [UIAlertAction actionWithTitle:@"open camrea"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
}];
UIAlertAction *openGallery = [UIAlertAction actionWithTitle:@"open gallery"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
}];
[alert addAction:openCamrea];
[alert addAction:openGallery];
[self presentViewController:alert animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud) 我一直UIAlertController在以前的应用程序中使用,但这次我遇到了一个奇怪的错误.这是我用来呈现它的代码:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:ALERT_TITLE_STRING message:message preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:OK_STRING style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alertController animated:YES completion:^{
}];
Run Code Online (Sandbox Code Playgroud)
一切都很好,但现在我的应用程序在最后一行崩溃了.这是错误:
此应用程序正在从后台线程修改autolayout引擎,这可能导致引擎损坏和奇怪的崩溃.这将在将来的版本中导致异常.
我没有autolayout在我的应用程序中使用.我不知道为什么我会收到这个错误.
有线索吗?
我想创建一个非常普通的效果,如下图所示:
说明:我要实现的效果包括一个视图,该视图在用户单击按钮时出现在屏幕底部(滑入):您仍然可以看到该视图后面的屏幕,但是它应用了“深色层” (例如黑度为60%的不透明度)的顶部。当用户单击“阻止”或“报告弃权”时(如本例所示),它将执行相应的操作。现在,当用户单击“取消”时,以及当他单击“深色层”上的任意位置时,都将使他回到屏幕上。
我想做的是:使用覆盖层展示一个新的视图控制器(但是它将使用比必要的更多的数据),但是我什至没有达到我们通常在应用程序上看到的那种效果。我不确定,但我想说要获得这种效果的最好方法是使用视图?
请问有人有主意吗?
谢谢,祝你有美好的一天,
Ĵ
我不确定这是否是罪魁祸首,但我对这个项目所做的最大改变是几天前升级到Swift 4.我知道我的UIAlertController消息在需要时显示多行,但今天我偶然意识到它们都变成了单行并且最后有省略号.由于我从API显示这些消息,我不能使用"\n".代码很简单;
let alert = UIAlertController(title: "Title", message: "Long message that must be shown as multiline", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in
alert.dismiss(animated: true, completion: nil)
}))
present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我检查了一些其他相关的问题,但没有一个对我有效.这个问题最近被问到同样的问题,但没有得到答案,并且有一个hacky解决方案作为解决方案发布;
所有警报对话框消息和textField都已更改为单行.请检查图像
任何有关检查内容的建议都非常感谢.