Iphone 我想在我的屏幕上弹出一个小视图(200x200),接受用户输入

Iphone 我想在我的屏幕上弹出一个小视图(200x200),接受用户输入,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,可能重复: 我希望能够在当前视图的顶部弹出一个小屏幕/视图,上面有一个UITextField和两个按钮。我想允许用户输入一些数据或取消 我不想用一个全新的屏幕来做这件事。有什么好办法可以实现这一目标吗?iOS API中是否提供了执行此操作的工具 任何链接到教程将不胜感激。我一直在谷歌上阅读,但我能找到的只是全屏模式视图的例子 谢谢, -代码检查和UIAlertViewDelegate类。他们应该做你想做的事 这是一个应该有用的方法 如果您需要文本输入(而不仅仅是按钮),请尝试您可以将UIAle

可能重复:

我希望能够在当前视图的顶部弹出一个小屏幕/视图,上面有一个UITextField和两个按钮。我想允许用户输入一些数据或取消

我不想用一个全新的屏幕来做这件事。有什么好办法可以实现这一目标吗?iOS API中是否提供了执行此操作的工具

任何链接到教程将不胜感激。我一直在谷歌上阅读,但我能找到的只是全屏模式视图的例子

谢谢, -代码

检查和UIAlertViewDelegate类。他们应该做你想做的事

这是一个应该有用的方法


如果您需要文本输入(而不仅仅是按钮),请尝试

您可以将UIAlertView类子类化为一个文本字段(或多个文本字段)

下面是自定义类的外观:(AlertPrompt.h)

AlertPrompt.m

#import "AlertPrompt.h"

@implementation AlertPrompt
@synthesize emailTextField, nameTextField;

- (id)initWithTitle:(NSString *)title delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle
{

if (self = [super initWithTitle:title message:@" \n\n\n" delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil])
{
    self.frame = CGRectMake(0, 0, 300, 400);
    UITextField *nameTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 
    UITextField *emailTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 80, 260.0, 25.0)];
    [nameTF setBackgroundColor:[UIColor whiteColor]]; 
    [nameTF setAutocorrectionType:UITextAutocorrectionTypeNo];
    [nameTF setPlaceholder:@"name"];
    [emailTF setBackgroundColor:[UIColor whiteColor]]; 
    [emailTF setAutocorrectionType:UITextAutocorrectionTypeNo];
    [emailTF setPlaceholder:@"email"];

    [self addSubview:nameTF];
    [self addSubview:emailTF];
    self.nameTextField = nameTF;
    self.emailTextField = emailTF;

    if (delegate) {
        self.emailTextField.delegate = delegate;
        self.nameTextField.delegate = delegate;
    }

    [nameTF release];
    [emailTF release];

}
return self;
}
- (void)show
{
    [nameTextField becomeFirstResponder];
    [super show];
}

 - (void)dealloc
{
    [nameTextField release];
    [emailTextField release];

    [super dealloc];
}
@end
您会注意到,我在init方法中将@“\n\n”作为参数传递,以便为要显示的文本字段留出空间。。因此,您必须根据要在提示中显示的文本字段的数量修改消息参数


希望这有助于

将第二个教程链接添加到我的上述答案中,以包含文本输入示例。这不是重复的。当某个白痴出现并这样做时,这是非常令人沮丧的。我的问题的答案如下。
#import "AlertPrompt.h"

@implementation AlertPrompt
@synthesize emailTextField, nameTextField;

- (id)initWithTitle:(NSString *)title delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle
{

if (self = [super initWithTitle:title message:@" \n\n\n" delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil])
{
    self.frame = CGRectMake(0, 0, 300, 400);
    UITextField *nameTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 
    UITextField *emailTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 80, 260.0, 25.0)];
    [nameTF setBackgroundColor:[UIColor whiteColor]]; 
    [nameTF setAutocorrectionType:UITextAutocorrectionTypeNo];
    [nameTF setPlaceholder:@"name"];
    [emailTF setBackgroundColor:[UIColor whiteColor]]; 
    [emailTF setAutocorrectionType:UITextAutocorrectionTypeNo];
    [emailTF setPlaceholder:@"email"];

    [self addSubview:nameTF];
    [self addSubview:emailTF];
    self.nameTextField = nameTF;
    self.emailTextField = emailTF;

    if (delegate) {
        self.emailTextField.delegate = delegate;
        self.nameTextField.delegate = delegate;
    }

    [nameTF release];
    [emailTF release];

}
return self;
}
- (void)show
{
    [nameTextField becomeFirstResponder];
    [super show];
}

 - (void)dealloc
{
    [nameTextField release];
    [emailTextField release];

    [super dealloc];
}
@end