在iOS8中显示UIPickerView与无法正常工作UIActionSheet
该代码适用于iOS7,但它在iOS8中不起作用.我确定这是因为在iOS8中不推荐使用UIActionSheet 而Apple建议使用UIAlertController.
但是,如何在iOS8中做到这一点?我应该用UIAlertController?
iOS7:

iOS8:

编辑:
uipickerview uiactionsheet ios uialertcontroller actionsheetpicker
我看到了更多的答案,但没有任何帮助.这是我的旧警报和行动
override func viewWillAppear(animated: Bool) {
if Reachability.isConnectedToNetwork() == true {
print("internet connection ok")
} else
{
print("internet not ok")
let alertView: UIAlertView = UIAlertView(title: "Alert ", message: "connect to internet", delegate: self, cancelButtonTitle: "settings", otherButtonTitles: "cancel")
alertView.show()
return
}
}
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int)
{
if buttonIndex == 0 {
//This will open ios devices wifi settings
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root")!)
}
else if buttonIndex == 1
{
//TODO for cancel
exit(0)
}
}
Run Code Online (Sandbox Code Playgroud)
在那我得到警告:
'UIAlertView'在iOS 9.0中已弃用.使用UIAlertController而不是UIAlertControllerStyleAlert的preferredStyle
我试过了 : …
我想阻止UIAlertController解雇.
我有一个UIAlertAction只是在UIAlertTextField中添加一个字符串,但是,一旦点击它就会解除视图控制器[不需要的].我已经尝试添加一个不需要的结果的NSNotification.
UIAlertAction *pasteMessage = [UIAlertAction actionWithTitle:@"Paste Message" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UITextField *textField = alertC.textFields.firstObject;
textField.text = [textField.text stringByAppendingString:[NSString stringWithFormat:@"%@", copiedString]];
}];
Run Code Online (Sandbox Code Playgroud)
我也尝试过将pasteMessage设置为:
[alertC canPerformAction:@selector(dismissViewControllerAnimated:completion:) withSender:pasteMessage];
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
UIAlertAction *paste = alertController.actions.firstObject;
if (paste) {
flag = NO;
} else {
flag = YES;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑,我不打算阻止攻击UIAlertAction我希望防止UIAlertController在点击上述行动时解雇.无论如何都可以启用/禁用该操作,但我的目标是UITextField通过按动作简单地将复制的消息粘贴到该动作中(因此我不希望它被解除)
我也意识到设置BOOL dismissViewControllerAnimated:只是将它设置为不动画视图控制器解雇,我不希望它暗示它是为了停止实际的解雇过程.简单地提供我尝试过与我的目标相关的事情.我还尝试在选择pasteMessage时使用复制的消息自动填充新的 textField 时会出现一个新的 ,它可以工作,但我觉得它太可能无法完成.UIAlertController UIAlertControllers
我正在使用Xcode 6开发iOS应用程序.
当我使用时UIAlertController,它可以在iPhone 6模拟器上运行良好,但在iPad模拟器上崩溃.
单击"共享"时出现问题,然后可能会崩溃.我该怎么解决?
这是我的代码:
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject] {
var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Share", handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
let shareMenu = UIAlertController(title: nil, message: "Share using", preferredStyle: .ActionSheet)
let twitterAction = UIAlertAction(title: "Twitter", style: UIAlertActionStyle.Default, handler: nil)
let facebookAction = UIAlertAction(title: "Facebook", style: UIAlertActionStyle.Default, handler: nil)
let emailAction = UIAlertAction(title: "Email", style: UIAlertActionStyle.Default, handler: nil)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
shareMenu.addAction(twitterAction)
shareMenu.addAction(facebookAction) …Run Code Online (Sandbox Code Playgroud) 我使用以下代码来呈现UIAlertController操作表,其中项目文本为红色.我已经使用了tint属性来设置颜色.
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alertController.view.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
高亮或选择时,文本颜色似乎默认为蓝色.这是正常的,我该怎么做呢?
由于UIActionSheet在iOS 8中的奇怪行为,我已经将UIAlertController与UIAction一起实现为按钮.我想改变UIAlertController的整个背景.但我找不到任何办法.
甚至尝试过,
actionController.view.backgroundColor = [UIColor blackColor];
Run Code Online (Sandbox Code Playgroud)
但是没有帮助我.关于这方面的任何意见都是值得注意的.
提前致谢.
我在iOS应用程序上使用PushNotification.我想在应用收到通知时显示UIalertcontroller.
我在AppDelegate中尝试以下代码:
[self.window.rootViewController presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是UIAlertcontroller正在根视图(第一个屏幕)中显示,而对于其他uiviewcontroller,我收到警告或应用程序崩溃.
我有一个带文本字段和两个按钮的AlertController:CANCEL和SAVE.这是代码:
@IBAction func addTherapy(sender: AnyObject)
{
let addAlertView = UIAlertController(title: "New Prescription", message: "Insert a name for this prescription", preferredStyle: UIAlertControllerStyle.Alert)
addAlertView.addAction(UIAlertAction(title: "Cancel",
style: UIAlertActionStyle.Default,
handler: nil))
addAlertView.addAction(UIAlertAction(title: "Save",
style: UIAlertActionStyle.Default,
handler: nil))
addAlertView.addTextFieldWithConfigurationHandler({textField in textField.placeholder = "Title"})
self.presentViewController(addAlertView, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是在文本字段为空时执行检查以禁用SAVE按钮,就像想要创建NewAlbum的iOS的图片应用程序一样.请有人能解释一下该怎么办?
我想要符合iOS 8中使用的UIAlertController,因为现在不推荐使用UIAlertView.有没有办法在不破坏对iOS 7的支持的情况下使用它?是否有某种if条件我可以检查iOS 8,否则为iOS 7支持做其他事情?
在iOS8之前,我们使用UIActionSheet来显示警报,现在我们需要使用UIAlertController.
当我们使用UIActionSheet时,我们可以通过将clickedButtonAtIndex与cancelButtonIndex进行比较来轻松处理用户在弹出窗口外点击的情况(这意味着他想要取消操作) - 如果用户确实在弹出窗口外按下了取消按钮索引在这个功能.
我们如何使用新的UIAlertController处理这些情况?我试图使用"完成"块,但它没有任何上下文.有一个简单的方法来处理这个?(除了"保存"某些一般变量中的动作状态).
ios ×10
objective-c ×3
ios8 ×2
ipad ×2
swift ×2
uialertview ×2
alert ×1
ios9 ×1
iphone ×1
swift3 ×1
uialertsheet ×1
uipickerview ×1