【问题标题】:UIAlertView ios8 only showing a line for keyboardUIAlertView ios8 只显示一行键盘
【发布时间】:2014-12-10 04:41:22
【问题描述】:

问题:

UIAlertView 在 iOS8 中只显示一行键盘

这是我的代码:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    UITextField *txtName = nil;

    if(buttonIndex == 1){ // save project name
        txtName = (UITextField *)[alertView textFieldAtIndex:0];

        if(txtName && txtName.text && [txtName.text length] > 0 && ![txtName.text isEqualToString:@" "]) {

            //SPAppDelegate *appdelegate = (SPAppDelegate*)[[UIApplication sharedApplication] delegate];
            NSString *filePath = nil;

            //if(![appdelegate isProjectNameAlreadyExist:txtName.text]){
            if(![SPUtility isProjectNameAlreadyExist:txtName.text]){
                //filePath = [appdelegate getProjectPathWthName:txtName.text];
                filePath = [SPUtility getProjectPathWthName:txtName.text];
                [self loadProjectList];
            }
            else{
                [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Project name already exists." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
            }
        }
        else{
            [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Project name is empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
        }
    }
}

问题一定出在这里***

-(void) launchProjectNameInputAlert{

    /*_alertView = nil;

    _alertView = [[UIAlertView alloc] initWithTitle:@"test" message:@"test1" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [_alertView show];*/

    _isShowAlert = YES; //boolean variable

    //_alertView =[[UIAlertView alloc] initWithTitle:@"ADD item" message:@"Put it blank textfield will cover this" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@" " message:@" " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;

    UITextField *txtName = [alertView textFieldAtIndex:0];
    txtName.text=@"";
    //txtName.tag = 1000;
    //[txtName setBackgroundColor:[UIColor blackColor]];
    [txtName setKeyboardAppearance:UIKeyboardAppearanceAlert];
    [txtName setAutocorrectionType:UITextAutocorrectionTypeNo];
    [txtName setTextAlignment:NSTextAlignmentLeft];
    txtName.placeholder = @"Project Name";
    [alertView addSubview:txtName];
    [alertView show];

}

有人可以检查一下吗?

这里是Image的链接供参考。

【问题讨论】:

  • 您能否提供一张图片或更好地阐述您的问题。脱离上下文时,您的代码毫无意义。你只显示键盘的一行是什么意思我假设它是一个文本字段但不确定,无论哪种方式,我们都不知道你的愿景是什么或你想要发生什么。
  • 我没有足够的声望在这里发送图片。我的视频编辑器上我的项目列表的警报弹出窗口现在在 ios7 上工作,现在在 ios8 上它只是弹出并显示一行您将在其中键入项目的行。您可以键入任何内容来制作项目。这是标准的 iOS 警报弹出窗口
  • 你可以链接图片供参考
  • 删除这一行:[alertView addSubview:txtName];,因为文本字段已经是一个子视图。

标签: ios objective-c uialertview


【解决方案1】:

科林;

首先,iOS 8 已弃用警报视图。为什么?因为新版本功能更强大,并且可以轻松定制。我了解您可能会觉得使用 clickedButtonAtIndex 来控制结果:但是,这些服务很容易使用新的 UIAlertController 进行转换。第一,您不需要委托,第二,一切都在块中完成。此外,相同的 UIAlertController 提供警报或操作表。它们不再分开。

这是一个例子:

UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; // Populates an action Sheet

UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert]; //Alert

然后您只需向它们添加操作

UIAlertAction *action = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];

将动作添加到 UIAlertController 并将其呈现给动画或 nil 视图:

[alertC addAction:action];
[self presentViewController:alertC animated:NO completion:nil];

有许多教程可以复制您想要的结果。

Use Your Loaf 似乎在分步教程中为那些坚持使用 UIAlertViews 的人做了出色的工作。

我建议利用这种新方法,因为您可以在块中处理所有代码,而不是冗长的 if 语句。它已被弃用是有原因的。

【讨论】:

  • 非常感谢,我要去看看,也许我可以让我的工作。我真的不知道从哪里开始改变。
  • 我正在试图弄清楚,我现在正在阅读它,代码太多,我不确定我在做什么。我不是编码员,刚刚读了一些关于它的书试图掌握它。我有人为我构建了一个视频编辑器,现在我无法让那个项目屏幕工作。我会尝试按照你链接中的步骤操作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-02
  • 1970-01-01
相关资源
最近更新 更多