我正在开发一个我已经用iOS-7发布的项目.但是现在因为操作表出现问题所以我现在正在实现UIAlertController.以下是我用来显示带有UIPicker的UIAlertController的代码.
alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:alertAction];
[alertController addAction:alertAction];
[alertController addAction:alertAction];
[alertController addAction:alertAction];
[pickerToolbar setFrame:CGRectMake(0, 0, self.view.frame.size.width-20, 44)];
[alertController.view addSubview:pickerToolbar];
[alertController.view addSubview:picker];
[alertController.view setBounds:CGRectMake(0, 0, self.view.frame.size.width, 485)];
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是我无法在其中添加datepicker.它与普通选择器不同,应用程序挂起.有关在UIAlertController中添加UIDatePicker的任何示例代码,请提供建议.提前致谢
我想在swift中更改UIAlertController中消息的颜色.默认为黑色我想将其更改为红色.
我的UIAlertController如下所示:
alert = UIAlertController(title: "", message: "Invalid Name", preferredStyle: UIAlertControllerStyle.Alert)
alert.view.tintColor = UIColor.blackColor()
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in
}))
self.presentViewController(alert, animated: true, completion: {
println("completion block")
})
Run Code Online (Sandbox Code Playgroud)
我想在上面的警告框中更改无效名称的颜色.
我想创建一个UIAlertController的子类但我疯了,因为我有构造函数的问题,这是我的子类:
class loginAlert : UIAlertController {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这个子类必须有构造函数:UIAlertController(title:String,message:String,preferredStyle:UIAlertControllerStyle),因为它是UIAlertController的子类,但是当我做的时候
loginAlert(title: "test", message: "test", preferredStyle: .Alert)
Run Code Online (Sandbox Code Playgroud)
我得到错误,为什么我错了?
我知道您可以在UIAlertController中禁用UIAlertAction按钮,但是一旦添加按钮,是否可以将其完全删除?
刚才我写了下面提供的代码.我想为以下代码生成输出,但是当我运行它时它崩溃了,它显示了nil.
class ViewController: UIViewController ,UITableViewDataSource{
var names = [String]()
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
title = "\"The List\""
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func addName(sender: AnyObject) {
let alert = UIAlertController(title: "New name", message: "Add one new name here", preferredStyle: .Alert)
let saveAction = UIAlertAction(title: "Save", style: .Default, handler: {(action:UIAlertAction) ->Void in
alert.addTextFieldWithConfigurationHandler{(textField:UITextField)->Void in
alert.view.endEditing(true)
let textField = alert.textFields?.last
self.names.append(textField!.text!) …Run Code Online (Sandbox Code Playgroud) 几天后,我在我的一个应用程序中看到了一个非常奇怪的行为.一添加第二个动作,UIAlertController就会崩溃.这是代码>
let alertController = UIAlertController.init(title: title, message: message, preferredStyle: .Alert)
for action in actions
{
alertController.addAction(action)
}
Run Code Online (Sandbox Code Playgroud)
actions是一个包含UIAlertAction元素的数组,在我的情况下2.我已经尝试重新排序操作以查看特定UIAlertAction对象是否存在问题,但是不,在添加第二个操作时应用程序总是崩溃.我像这样创建它们:
let cancelAction = UIAlertAction.init(title: "Cancel", style: .Cancel)
{ (action:UIAlertAction!) -> Void in
print("User cancelled action");
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是我创建数组的方式:
showAlertView("Proceed", message: proceedMessage, actions: [cancelAction, proceedAction])
Run Code Online (Sandbox Code Playgroud)
编辑结束
大多数代码来自Apple教程,几乎没有变化.调试器立即跳转到class AppDelegate: ...没有其他信息然后SIGABRT的行,在崩溃日志中我看到:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Filtered syslog:
None found
Last Exception Backtrace:
0 CoreFoundation 0x1832c6db0 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x18292bf80 objc_exception_throw …Run Code Online (Sandbox Code Playgroud) 我为iOS9编写的代码非常好用:
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Select source"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alert.view.backgroundColor = DARK_BLUE;
alert.view.tintColor = NEON_GREEN;
UIView *subview = alert.view.subviews.firstObject;
UIView *alertContentView = subview.subviews.firstObject;
alertContentView.backgroundColor = DARK_BLUE;
alertContentView.layer.cornerRadius = 10;
Run Code Online (Sandbox Code Playgroud)
我的观点是UIAlertController继承UIViewController,并UIViewController具有UIView可以改变的属性.这是有效的.现在,继承UIViewController的视图有自己的子视图,contentView显示为Alert.我可以在子视图数组中以firstObject的形式访问它.现在,为什么发送背景颜色的消息不再起作用?有谁知道一些新的解决方案?
如果我打电话(在一个UIViewController)
alert.dismiss(animated: false, completion: nil)
print("executed after dismiss?")
Run Code Online (Sandbox Code Playgroud)
鉴于警报是先前提出的UIAlertController,dismiss方法是否同步执行?
我可以这样做:
alert.dismiss(animated: false, completion: nil)
let newAlert = UIAlertController(...)
present(newAlert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在呈现时不必担心问题newAlert?
我正在开发一个应用程序,但它是一个相当古老的应用程序.客户不想花太多时间,所以我正在寻找一个简单快速的解决方案来解决这个问题.
用户必须为他们的配置文件写一个摘要,因此他们需要一个很大的空间来写入.整个应用程序是使用AlertController弹出窗口构建的,所以我想用一个更大的多行UITextField替换单行UITextField.
我能做些什么来实现这一目标?我目前添加了以下代码:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"Enter your summary" preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"Summary";
textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
textField.text = _summaryLabel.text;
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:textField attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant: 110.0];
[textField addConstraint:constraint];
[textField layoutIfNeeded];
}];
Run Code Online (Sandbox Code Playgroud)
这意味着UITextField实际上更大,但它不是多线,它也是垂直居中的文本.我该怎么办?
let location = CLLocationCoordinate2D(latitude: 32.075300, longitude: 34.782563)
@IBAction func DirectionsTolocationButton(_ sender: Any) {
// Create the AlertController and add its actions like button in ActionSheet
let ActionSheet = UIAlertController(title: "Please Select A Navigation Service.", message: nil, preferredStyle: .actionSheet)
let AppleMapsButton = UIAlertAction(title: "Apple Maps", style: .default) { action -> Void in
let destinationName = (self.barNameTemplate )
self.openMapsAppWithDirections(to: self.CoordinatesTemplate, destinationName: destinationName)
print("Apple Map Chosen!")
}
let WazeButton = UIAlertAction(title: "Waze", style: .default) { action -> Void in
func openWaze(location : CLLocationCoordinate2D) …Run Code Online (Sandbox Code Playgroud) ios ×9
swift ×6
objective-c ×2
function ×1
ios10 ×1
sigabrt ×1
uicolor ×1
uidatepicker ×1
uipicker ×1