-1

Possible Duplicate:
UITextField in UIAlertView on iPhone - how to make it responsive?
UITextField in UIAlertView alternative?

i want to put TextField in AlertView when the alert is displayed to the users.

Community
  • 1
  • 1
Nishith Shah
  • 523
  • 3
  • 16

7 Answers7

2

Since iOS5 you can use UIAlertViewStyle to add the different Textinput into the UIAlertview

Example Link

Vinh
  • 944
  • 13
  • 34
0

from UITextField in UIAlertView on iPhone - how to make it responsive?

UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];

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];
[dialog release];
[nameField release];
Community
  • 1
  • 1
Mujah Maskey
  • 8,654
  • 8
  • 40
  • 61
0

Just add it as a subView to the UIAlertView object with the frame size that you desire !

Legolas
  • 12,145
  • 12
  • 79
  • 132
0

I came up with this, its a little long, but I set it and forgot and it works...

alertView = [[UIAlertView alloc] initWithTitle:t message:@"" delegate:self     cancelButtonTitle:@"CANCEL" otherButtonTitles:@"OK", nil];

pinField = [[UITextField alloc] initWithFrame:CGRectMake(20, 38, 244, 31)];
pinField.backgroundColor = [UIColor whiteColor];
[alertView show];


[alertView insertSubview:pinField atIndex:2];


NSArray * subviews = [alertView subviews];
UILabel * label1 = [subviews objectAtIndex:1];
UIImageView * bg = [subviews objectAtIndex:0];
UIView * button1 = [subviews objectAtIndex:4];
UIView * button2 = [subviews objectAtIndex:5];
float height = 0;
height = 16 + label1.frame.size.height;
CGRect frame = label1.frame;
frame.origin.y = 8;
label1.frame = frame;

frame = pinField.frame;
frame.origin.y = height;
pinField.frame = frame;

height += 8 + frame.size.height;
frame = button1.frame;
frame.origin.y = height;
button1.frame = frame;

frame = button2.frame;
frame.origin.y = height;
button2.frame = frame;

height += 8 + frame.size.height;
frame = alertView.frame;
frame.size.height = height +8;
alertView.frame= frame;

frame = bg.frame;
frame.size.height = alertView.frame.size.height;
bg.frame = frame;

[pinField release];
[alertView release];
Jesse Black
  • 7,966
  • 3
  • 34
  • 45
0

Create a custom class which inherits from UIAlertview and add a textfield element to it.

Then write this method :

-(id)init
{
    txtField = [[UITextField alloc] initWithFrame: CGRectZero]; // your frame here
    [self addSubview: txtField];

    return self;
}

This might help. Now create an object of this class in some other class and test it.

Luke
  • 11,426
  • 43
  • 60
  • 69
Abhishek Bedi
  • 5,205
  • 2
  • 36
  • 62
0
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Save As" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
self.textfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[self.textfield setBackgroundColor:[UIColor whiteColor]];

[myAlertView addSubview:self.textfield];
[myAlertView show];
[myAlertView release];
Nari
  • 213
  • 5
  • 16
0
UIAlertView *customAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

[txtField setBackgroundColor:[UIColor whiteColor]];

[customAlertView addSubview:txtField];

[customAlertView show];

[customAlertView release];
Luke
  • 11,426
  • 43
  • 60
  • 69
Anil Kothari
  • 7,653
  • 4
  • 20
  • 25