我的应用需要在不同时间向用户显示一些信息.我决定使用AlertControllers,但我无法同时显示两个警报控制器.因此,我需要知道是否显示警报控制器,关闭它并打开另一个警报控制器.
到目前为止我已经这样做了.我正在使用self.presentedViewController检查是否显示AlertController.但我无法弄清楚如何关闭它.我试过了
self.presentedViewController?.removeFromParentViewController()
Run Code Online (Sandbox Code Playgroud)
和
self.presentedViewController?.delete(self.presentedViewController)
Run Code Online (Sandbox Code Playgroud)
没有运气.有人可以帮帮我吗?谢谢
8之前的iOS版本允许我创建一个UIActionsheet显示一组按钮,一些空格,然后是取消按钮的版本.像这样的东西:

但是在iOS 8中,当我尝试创建相同的外观时,我最终会得到如下所示的内容:

iOS 8中的代码如下所示:
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alertVC.view setTintColor:[UIColor copperColor]];
UIAlertAction* notifyViaPush = [UIAlertAction
actionWithTitle:@"Send Alert to my phone"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alertVC dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* notifyViaEmail = [UIAlertAction
actionWithTitle:@"Notify me by email"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alertVC dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
[alertVC dismissViewControllerAnimated:YES completion:nil];
}];
[alertVC addAction:notifyViaPush];
[alertVC addAction:notifyViaEmail];
[alertVC addAction:cancel];
[self presentViewController:alertVC animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
如何使用UIAlertController对按钮进行分组并在操作和取消按钮之间留出一些空间?
我正在使用UIToolbar中的UIAlertController向用户提供一个选项列表,其中包含一个首选的操作表样式.呈现时,弹出箭头被切掉,其角落呈圆形,有两个不同的半径:

我用来呈现它的代码直接来自文档,据我所知:
UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleActionSheet];
NSArray *actions = @[
[UIAlertAction actionWithTitle:@"Take a Photo"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {}],
[UIAlertAction actionWithTitle:@"Choose from Album"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {}],
[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {}]
];
for (UIAlertAction *action in actions) {
[alertController addAction:action];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
alertController.modalPresentationStyle = UIModalPresentationPopover;
alertController.popoverPresentationController.barButtonItem = myBarButtonItem;
}
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
这是一个已知的错误?我在iOS 8.2和iOS 8.1和8.2上的模拟器上尝试过物理iPad.
我有一个UITableView,在委托(视图控制器)中,我实现了该功能
tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
Run Code Online (Sandbox Code Playgroud)
然后我测试编辑风格
if editingStyle == UITableViewCellEditingStyle.Delete {
// do deleting stuff here
}
Run Code Online (Sandbox Code Playgroud)
作为删除的一部分,我要求用户确认,如果他们选择"是",则与该行相关的项目将被删除,如果他们选择否,则重置编辑样式.
var alert = UIAlertController(title: "Delete Item", message: "Are you sure you want to delete the selected item?", preferredStyle: UIAlertControllerStyle.Alert)
//delete
alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Destructive, handler: { (action: UIAlertAction!) -> Void in
println("Yes action was selected")
//delete my object and remove from the table
}))
//cancel
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (action: UIAlertAction!) -> Void in
//reset editing …Run Code Online (Sandbox Code Playgroud) 我正在开发适用于iPhone 6S/6S Plus /和iPad外形的通用应用程序.通常,在仅限iPhone的应用程序上呈现动作表/警报视图是一种简单的方式.但是当我尝试在iPad上显示这些应用程序时,我的应用程序崩溃,返回以下错误:
"终止应用程序由于未捕获的异常'NSGenericException’,原因是:"你的应用程序的风格UIAlertControllerStyleActionSheet的提出了UIAlertController()一UIAlertController的这种风格的modalPresentationStyle是UIModalPresentationPopover你必须通过报警控制器的popoverPresentationController提供位置信息,该酥料饼.您必须提供sourceView和sourceRect或barButtonItem.如果在显示警报控制器时不知道此信息,您可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供它.
据我所知,当应用程序在iPad上运行而不是传统的操作表时,我必须显示一个弹出窗口.为了上下文,操作表由自定义单元格中的按钮显示,该按钮位于tableview中.
在通用应用程序中处理UIAlertControllers/Action Sheets/UIPopoverControllers的最佳方法是什么?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *titleToUse = @"";
// switch (self.openGroup) {
// case 0:
// titleToUse = [self.deviceListData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// case 1:
// titleToUse = [self.computersData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// case 2:
// titleToUse = [self.mobileData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// case 3:
// titleToUse = [self.smartData[indexPath.row] valueForKey:@"deviceName"];
// break;
//
// default:
// break;
// }
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:titleToUse …Run Code Online (Sandbox Code Playgroud) objective-c uiactionsheet uipopovercontroller ios uialertcontroller
我想要这样的警报对话框。其中包含一个可点击的链接,例如蓝色突出显示的文本。当用户单击该文本时,它将在浏览器中打开一个链接。为此,我正在使用第三方库SimpleAlert
这是我的代码...
func popUpMsg(){
let msg = "\n Hi Rahul! Welcome back to the early access queue for the app, Once you've been accepted into the beta, we'll notify you using the contact info you have on file with Facebook. \n\n But just a second, if you haven't already done so, you can increase your odds of jumping ahead in the queue by telling us a little about yourself. Please complete our 4-question survey to give it a shot. …Run Code Online (Sandbox Code Playgroud) 我很确定这是一个框架错误,但只是为了确保 - 其他人是否有这个问题并找到了解决方案?
当我点击通用链接并打开时 - 我在控制台中收到以下错误:
尝试在取消分配时加载视图控制器的视图是不允许的,并且可能导致未定义的行为()
在应用程序中此时没有使用UIAlertController - 它只是一个具有Web视图的视图控制器 - 这就是全部.
有人可以帮助我,还是应该发送错误报告?
布里克
看看我的下面的代码.我正在尝试使用uialertviewcontroller.Now添加文本字段当我的两个文本字段中没有输入时我需要禁用两个操作按钮.怎么做?
请提出一些可能的解决方案.谢谢!!
是否可以更改UIAlertController其ViewController呈现时的标题或消息文本.
例如,当用户按下带有此消息的按钮时,我会发出警报:
"等待兑换代码"
然后我使用Alamofire发出请求并获取代码,在我拥有它之后,我想从警报中更改消息而不会有任何不知情并再次呈现它,例如新的消息文本是:
"您的兑换码是:########"
更新
这是我的代码:
@IBAction func offerAction(_ sender: UIButton) {
var code: String = "Generating códe"
let message: String = "El código para redimir esta oferta es: \(code)"
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "Accept", style: .default, handler: nil)
let redirect = UIAlertAction(title: "Website", style: .default) { (_) in
// TODO open url web
}
if offer.redeemOfferOnline == .yes {
alert.addAction(redirect)
}
alert.addAction(okAction)
present(alert, …Run Code Online (Sandbox Code Playgroud) 在Uialertcontroller中没有类似于addtextfield方法的方法。我尚未找到有关如何自定义MDCAlertControllers的任何示例。有人有主意吗?