相关疑难解决方法(0)

iPhone上的UIAlertView中的UITextField - 如何使其响应?

我将UITextField放入UIAlertView并将其向上移动,以便键盘不会使用以下代码覆盖它:

[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
UITextField * nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
Run Code Online (Sandbox Code Playgroud)

我还有以下代码来处理警报视图:

- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex{    
    NSLog(@"%d", (int) buttonIndex);
    if (buttonIndex == 1) { // OK pushed
        NSLog([alert textField].text); // does not log anything
    } else {
        // Cancel pushed
}}
Run Code Online (Sandbox Code Playgroud)

我还有一个UIAlertViewExtended.h文件,其中包含:

@class UITextField, UILabel;

@interface UIAlertView(Extended)

-(UITextField *)textField;

@end
Run Code Online (Sandbox Code Playgroud)

我的问题是如何获取用户输入的文本以及如何解除键盘?

谢谢,本

iphone cocoa-touch

24
推荐指数
4
解决办法
5万
查看次数

如何使用UIAlertStylePlainTextInput样式格式化UIAlertView中的两个以上按钮?

UIAlertView在我的应用程序中添加了一个抓取用户输入,但我不确定如何添加第三个按钮.理想情况下,三个按钮将水平跨越警报,或者两个按钮位于"取消"按钮上方.下面的代码片段是我用来添加的代码片段UIAlertView.

- (IBAction)initiateSave{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Archive" 
                                          message:@"Enter a name to save this as:" 
                                          delegate:self 
                                          cancelButtonTitle:@"Cancel" 
                                          otherButtonTitles:@"Save Session",@"Save",nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField * alertTextField = [alert textFieldAtIndex:0];
    alertTextField.keyboardType = UIKeyboardTypeDefault;
    alertTextField.placeholder = @"eg. My awesome file...";
    alert.tag = 1;
    [alert show];
    [alert release];
    self.name = [[alert textFieldAtIndex:0]text];
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

iphone objective-c uialertview ios ios5

9
推荐指数
1
解决办法
3979
查看次数

标签 统计

iphone ×2

cocoa-touch ×1

ios ×1

ios5 ×1

objective-c ×1

uialertview ×1