标签: uialertcontroller

UIPopover如何使用这样的按钮制作弹出窗口?

在此输入图像描述

我想知道如何用这样的按钮创建一个popover.

回答:

UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: nil 
                                                          delegate: self
                                                 cancelButtonTitle: nil 
                                            destructiveButtonTitle: nil 
                                                 otherButtonTitles: @"Take Photo",
                                                                    @"Choose Existing Photo", nil];

[actionSheet showFromRect: button.frame inView: button.superview animated: YES];
Run Code Online (Sandbox Code Playgroud)

委托对象类中的其他位置......

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
         // take photo...
    } 
    else if (buttonIndex == 1) {
         // choose existing photo...
    }
}
Run Code Online (Sandbox Code Playgroud)

uiactionsheet ipad uipopovercontroller ios uialertcontroller

19
推荐指数
1
解决办法
2万
查看次数

如何使用UIAlertController

我想在吃豆子游戏我从一些网站上得到了使用此代码,但不得不改变UIAlertViewUIAlertController除了下面的代码有两个错误,我不知道如何解决(我真的很新的节目,觉得这是一个真的新手问题 - 抱歉!)

第一个错误在第4行:选择器没有已知的类方法 alertControllerWithTitle

第二个错误出现在最后一行:没有可见的接口声明选择器 show

- (void)collisionWithExit: (UIAlertController *)alert {

    if (CGRectIntersectsRect(self.pacman.frame, self.exit.frame)) {

        [self.motionManager stopAccelerometerUpdates];

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Congratulations"
                                                        message:@"You've won the game!"
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil
                                              preferredStyle:UIAlertControllerStyleAlert];
        [alert show];
    }
}
Run Code Online (Sandbox Code Playgroud)

objective-c uialertview ios swift uialertcontroller

19
推荐指数
2
解决办法
4万
查看次数

UIAlertController泄漏

UIAlertController通过UIViewController使用以下方法创建类别来添加我的应用程序:

- (void)showAlertViewWithTitle:(NSString *)title
                       message:(NSString *)message
                       actions:(NSArray *)alertActions
{
   UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title ? : @"" message:message preferredStyle:UIAlertControllerStyleAlert];

   if (alertActions.count) {
      for (UIAlertAction *action in alertActions) {
         [alertController addAction:action];
      }
   } else {
      UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
      [alertController addAction:action];
   }

   [self presentViewController:alertController animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

起初,一切看起来都很棒但是当我用Instruments分析泄漏时,每次调用这个方法时,都会出现一些泄漏:

在此输入图像描述

以下是调用的showAlertViewWithTitle:message:actions:方法

[self showAlertViewWithTitle:nil message:@"Test message" actions:nil];
Run Code Online (Sandbox Code Playgroud)

知道为什么我得到所有这些泄漏?

- 编辑 -

我在一个示例项目中尝试了以下内容:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"message"
                                                   delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
Run Code Online (Sandbox Code Playgroud)

我得到了同样的泄漏.我真的不确定发生了什么......

objective-c ios uialertcontroller

18
推荐指数
1
解决办法
3485
查看次数

使用UIAlertControllerStyle.ActionSheet在UIAlertController中取消按钮

我想在我的UIAlert中添加一个单独的取消按钮.

我知道如何使用UIActionSheet,但UIAlert也应该可以,对吗?

var sheet: UIActionSheet = UIActionSheet();
    let title: String = "...";
    sheet.title  = title;
    sheet.delegate = self;
    sheet.addButtonWithTitle("Cancel");
    sheet.addButtonWithTitle("...")
    sheet.cancelButtonIndex = 0;
    sheet.showInView(self.view);
Run Code Online (Sandbox Code Playgroud)

这将有一个...按钮和一个分开的取消按钮.

所以有人知道如何做到这一点

    var alert = UIAlertController(title: "...", message: "....", preferredStyle: UIAlertControllerStyle.ActionSheet)
Run Code Online (Sandbox Code Playgroud)

我是xcode和swift的新手很抱歉,如果这个问题是愚蠢或任何事情......

xcode ios swift uialertcontroller uialertaction

18
推荐指数
2
解决办法
3万
查看次数

UIAlertController更改字体颜色

这是我创建UIAlertController的代码

    // Create the alert controller
    var alertController = UIAlertController(title: "Are you sure you want to call \(self.number)?", message: "", preferredStyle: .Alert)

    // Create the actions
    var okAction = UIAlertAction(title: "Call", style: UIAlertActionStyle.Default) {
        UIAlertAction in
        var url:NSURL = NSURL(string: "tel://\(self.number)")!
        UIApplication.sharedApplication().openURL(url)
    }

    var cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
        UIAlertAction in

    }

    // Add the actions
    alertController.addAction(okAction)
    alertController.addAction(cancelAction)

    // Present the controller
    self.presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何更改取消和调用操作的文本颜色.标题文本目前为黑色,取消和呼叫按钮为白色.我正在努力让它们全黑,以提高能见度.有任何想法吗?谢谢!

swift ios8 uialertcontroller

18
推荐指数
4
解决办法
2万
查看次数

UIAlertController不使用Swift 3.0

我有以下警报方法.

static func notifyUser(_ title: String, message: String) -> Void
{
    let alert = UIAlertController(title: title,
                                  message: message,
                                  preferredStyle: UIAlertControllerStyle.alert)

    let cancelAction = UIAlertAction(title: "OK",
                                     style: .cancel, handler: nil)

    alert.addAction(cancelAction)
    self.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,说是有一个额外的参数animatedpresentViewController方法,但是我把它拿出来的时候,它仍然没有清除错误,然后有人告诉我completion是一个额外的参数.

ios swift uialertcontroller swift3

18
推荐指数
3
解决办法
3万
查看次数

在iOS 8中自定义UIAlertController以包含UITableView等标准元素

我习惯UIAlertViews通过[ alert setValue:someView forKey:@"accessoryView"]方法来定制.这为UIAlertViews创建了具有自定义高度的可自定义内容.但它只适用于iOS7及以下版本.在iOS8中UIAlertController已经接管了,我不能再自定义它了,它会削减它的高度UIAlertView.

是不是因为误用了UIAlertController,或者我该怎么做呢?我试图在UIAlertController中包含一个UITableView UIAlertControllerStyleAlert.

谢谢.

customization uialertview ios8 uialertcontroller

17
推荐指数
2
解决办法
4万
查看次数

如何使用目标c从UIAlertController中的文本字段访问输入?

我正在将所有内容从AlertView更改为AlertController,但我无法在线找到任何用于检索用户在AlertController的文本字段中输入内容的内容.这是我有的:

if ([UIAlertController class]) {
            UIAlertController *alertControllerK2 = [UIAlertController
                                                    alertControllerWithTitle:@"\u00A0"
                                                    message:@"Please enter the first number."
                                                    preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *K2okAction = [UIAlertAction
                                         actionWithTitle:@"OK"
                                         style:UIAlertActionStyleDefault
                                         handler:nil];
            [alertControllerK2 addTextFieldWithConfigurationHandler:^(UITextField *K2TextField)
             {
                 K2TextField.placeholder = NSLocalizedString(@"Please enter the first number.", @"Please enter the first number.");
             }];
            [alertControllerK2 addAction:K2okAction];
            [self presentViewController:alertControllerK2 animated:YES completion:nil];
        } else {
            UIAlertView *alertK2;
            alertK2 = [[UIAlertView alloc]
                       initWithTitle:@"\u00A0"
                       message:@"Please enter the first number."
                       delegate: self
                       cancelButtonTitle:@"OK"
                       otherButtonTitles:nil];
            alertK2.alertViewStyle=UIAlertViewStylePlainTextInput;
            [alertK2 show];
        }
Run Code Online (Sandbox Code Playgroud)

问题是K2TextField是在UIAlertController中定义的,所以我无法在该代码之外访问它.但是,如果我尝试预定义它,我会收到一条错误消息.任何帮助将不胜感激!

input ios8 uialertcontroller

17
推荐指数
2
解决办法
1万
查看次数

如何向UIAlertController添加操作并获取操作结果(Swift)

我想设置一个UIAlertController带有四个动作按钮,按钮的标题设置为"心形","黑桃","钻石"和"俱乐部".按下按钮时,我想返回其标题.

总之,这是我的计划:

// TODO: Create a new alert controller

for i in ["hearts", "spades", "diamonds", "clubs"] {

    // TODO: Add action button to alert controller

    // TODO: Set title of button to i

}

// TODO: return currentTitle() of action button that was clicked
Run Code Online (Sandbox Code Playgroud)

xcode ios swift uialertcontroller

17
推荐指数
2
解决办法
4万
查看次数

如何改变UIAlertController的高度?

我创建了一个UIAlertController

let alertC = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alertC.addTextFieldWithConfigurationHandler(addTextField)
alertC.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
alertC.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: okButton))
presentViewController(alertC, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

但之后我想改变UIAlertController的高度?我怎样才能做到这一点?

height swift uialertcontroller

16
推荐指数
2
解决办法
2万
查看次数