Warning on Alertview [duplicate] - iphone

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
warning: 'UIAlertView' may not respond to '-addTextFieldWithValue:label:'
I am using below code for put textfield in AlertView, it gives a warning like "UIAlertView may not respond - addTextFieldWithValue: label:" & "UIAlertView may not respond - textFieldAtIndex"...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Email" message:#""
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alert addTextFieldWithValue:#"" label:#"Email"];
// Username
textfieldName = [alert textFieldAtIndex:0];
textfieldName.keyboardType = UIKeyboardTypeEmailAddress;
textfieldName.keyboardAppearance = UIKeyboardAppearanceAlert;
textfieldName.autocorrectionType = UITextAutocorrectionTypeNo;
[alert show];
please help!

there is no method "addTextFieldWithValue" for uialertview
if you need to modify your alert view have a look at my blog here - http://www.makebetterthings.com/blogs/iphone/add-uitextfield-in-uialertview/

These is no such methods like addTextFieldWithValue in UIAlertView.

[alert addTextFieldWithValue:#"" label:#"Email"]; is a private api. My app got rejected because of using this.
Use this
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"Twitter"
message:#"\n\n\n\n"
delegate:self
cancelButtonTitle:#""
otherButtonTitles:#"", nil];
myAlert.frame = CGRectMake( 0, 0, 300, 260);
textfieldName = [[UITextField alloc] initWithFrame:CGRectMake(13, 95, 260, 25.0)];
[textfieldName setBackgroundColor:[UIColor whiteColor]];
textfieldName.placeholder = #"xyz";
textfieldName.keyboardType = UIKeyboardTypeAlphabet;
textfieldName.keyboardAppearance = UIKeyboardAppearanceAlert;
textfieldName.autocorrectionType = UITextAutocorrectionTypeNo;
textfieldName.delegate = self;
textfieldName.tag = 1;
[myAlert addSubview:textfieldName];

**I use in my project < and use and implement
use in .h file**
#protocol InputAlertViewDelegate
-(void)handleEnteredValue:(NSString*)_value;
-(void)handleCancellation;
#end
#interface InputAlertView : UIAlertView <UIAlertViewDelegate> {
UITextField *textField;
id<InputAlertViewDelegate> caller;
} #property(nonatomic, retain) UITextField *textField;
#property(nonatomic, retain) id<InputAlertViewDelegate> caller;
-(NSString*) theText;
-(void) prepare;
-(void) makePassword;
-(void) makeTelephone;
+(InputAlertView*) inputAlertViewWithTitle:(NSString*)_title initialFieldText:(NSString*)_text caller:(id<InputAlertViewDelegate>)_caller;
**use in .m file**
+(InputAlertView*) inputAlertViewWithTitle:(NSString*)_title initialFieldText:(NSString*)_text
caller:(id<InputAlertViewDelegate>)_caller
{
InputAlertView *_alert =
[[[self alloc] initWithTitle:_title message:#"\n" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil] autorelease];
_alert.delegate = _alert;
_alert.caller = _caller;
[_alert prepare];
_alert.textField.text = _text;
return _alert;
}
-(void)prepare
{
self.textField = [[[UITextField alloc] initWithFrame:CGRectMake(12.0, 45, 260.0, 30.0)] autorelease];
[textField setBackgroundColor:[UIColor clearColor]];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
[self addSubview:textField];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
[self setTransform:myTransform];
-(void) show{
[textField becomeFirstResponder];
[super show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 1){ [self.caller handleCancellation];
} else{
[self.caller handleEnteredValue:[self theText]];
}
}

Related

How to put uitextfield for user id and password in UIAlertView?

I am creating an application where i need to create two UITextField or TextBox for User id and password inside a UIAlertView for User login.I have tried something but here the textfield created becomes very big and almost cover the whole alert view.Please somebody help me how to organize the textfield and labels etc inside the alert view. I need like - there should be a small textfield against the label "User Id" and "Password". So how to do that? please help me. Thanx in advance.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"User Login" message:#"Please Enter the Following \n\n\n\n\n\n\n" delegate:self cancelButtonTitle:#"Close" otherButtonTitles:#"Sign In", nil];
UILabel *lblUserName = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, 85, 21)];
lblUserName.tag =2;
//lblUserName.backgroundColor = [UIColor darkGrayColor];
lblUserName.font = [UIFont systemFontOfSize:15.0];
lblUserName.text = #"User Name:";
lblUserName.textColor=[UIColor whiteColor];
//[lblUserName setFont:[UIFont fontWithName:#"TimesNewRomanPS-boldMT" size:8]];
lblUserName.backgroundColor = [UIColor clearColor];
[alert addSubview:lblUserName];
UITextField *txtUserName;
//if(txtUserName==nil)
txtUserName = [[UITextField alloc] initWithFrame:CGRectMake(89, 50, 160, 30)];
txtUserName.tag = 3;
txtUserName.borderStyle = UITextBorderStyleBezel;
txtUserName.textColor = [UIColor whiteColor];
txtUserName.font = [UIFont systemFontOfSize:12.0];
txtUserName.placeholder = #"User ID";
[alert addSubview:txtUserName];
alert.tag=3;
[alert show];
[alert release];
As of iOS5, UIAlertView supports a login screen using the Alert Style UIAlertViewStyleLoginAndPasswordInput.
More information in the UIAlertView Class Reference
UIAlertView *alert =[UIAlertView alloc] init];
alert.delegate =self //make sure to add the UIAertViewDelegate in the .h file
alert.alertViewStyle =UIAlertViewStyleLoginAndPasswordInput;
alert.message =#"Please login";
[alert show];
[alert release];
Then in the clickedButtonAtIndex delegate method:
{
UITextField *username = [alertView textFieldAtIndex:0];
UITextfield *password = [alertView textFieldAtIndex:1];
NSLog(#"Username %"# password %"#,username.text, password.text);
}

How do you format more than two buttons inside an UIAlertView with the UIAlertStylePlainTextInput style?

I've added a UIAlertView in my application that grabs user input but I'm unsure as to how I can add a third button. Ideally the three buttons would be across the alert horizontally or two would be above the "cancel" button. The code snippet below is what I'm using to add the 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];
}
Apple really doesn't want you messing with UIAlertView. If the way it naturally formats itself doesn't meet your needs, consider putting up a custom presented ("modal") view instead.
This can definitely be achieved, first of all you'll need to set up something like this.
// Create Alert
UIAlertView* av = [UIAlertView new];
av.title = #"Find";
// Add Buttons
[av addButtonWithTitle:#"Cancel"];
[av addButtonWithTitle:#"Find & Bring"];
[av addButtonWithTitle:#"Find & Go"];
[av addButtonWithTitle:#"Go to Next"];
// Make Space for Text View
av.message = #"\n";
// Have Alert View create its view heirarchy, set its frame and begin bounce animation
[av show];
// Adjust the frame
CGRect frame = av.frame;
frame.origin.y -= 100.0f;
av.frame = frame;
// Add Text Field
UITextField* text = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
text.borderStyle = UITextBorderStyleRoundedRect;
[av addSubview:text];
[text becomeFirstResponder];
QUOTED FROM...
https://stackoverflow.com/a/412618/716216
Then you'll want to animate moving the UIAlertView up when the keyboard is called up... something like this...
-(void)keyboardWillShow: (id) notification {
if(showAlert==YES)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[createNewAlert setTransform:CGAffineTransformMakeTranslation(0,-60)];
[createNewAlert show];
[UIView commitAnimations];
}
}
-(void)keyboardWillHide: (id) notification {
if(showAlert==YES)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[createNewAlert setTransform:CGAffineTransformMakeTranslation(0,+60)];
[UIView commitAnimations];
}
}
QUOTED FROM... https://stackoverflow.com/a/3844956/716216
Of course you can find additional info on custom UIAlertViews in the following Apple sample code!
https://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html
Good Luck!!!!
It's works fine to me. After showing lot of thread finally i found solution
UIAlertView* getWebUrl = [[UIAlertView alloc] initWithTitle:#"Enter URL"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Save",
#"Save Url", nil];
getWebUrl.transform=CGAffineTransformMakeScale(1.0, 0.75);
getWebUrl.alertViewStyle=UIAlertViewStylePlainTextInput;
[getWebUrl show];
and align buttons and textfield after present alertview
-(void)willPresentAlertView:(UIAlertView *)alertView {
for (UIView *view in alertView.subviews) {
if ([view isKindOfClass:[UITextField class]]||
[view isKindOfClass:[UIButton class]] || view.frame.size.height==31) {
CGRect rect=view.frame;
rect.origin.y += 65;
view.frame = rect;
}
}
}
I don't think you can manually resize a UIAlertView, but a trick I use for including a UIActivityIndicatorView is to use "/n" in the message string to make the "message" larger (one extra line per each "/n"), therefore making enough space for everything else.
This is somewhat tricky, Here is the solution for this.You need to use \n in the message string to increase the height of the UIAlertView.
- (IBAction)initiateSave{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Archive"
message:#"\n\n\n\n\n" // Trick to increase the height
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Save Session",#"Save",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
After increasing the height of Alert, now you can add a label to set the message in the label : "Enter a name to save this as:" at appropriate position.
[alert addSubView: messageLbl];
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];
}
Here, a bit late but should do the trick. (Work for me).
Create UIAlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"TITLE"
message:#"BODY"
delegate:self
cancelButtonTitle:#"CANCEL"
otherButtonTitles:#"OK",#"SEARCH",nil];
alert.tag = kAlertTag;
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *alertTextField = [alert textFieldAtIndex:0];
alertTextField.keyboardType = UIKeyboardTypeDefault;
alertTextField.placeholder = #"ENTER STH";
[alert show];
[alert release];
And implement delegate method.
-(void)willPresentAlertView:(UIAlertView *)alertView {
if (alertView.tag == kAlertTag) {
[alertView setFrame:CGRectMake(17, 30, 286, 188)];
NSArray *subviewArray = [alertView subviews];
UILabel *messageLB = (UILabel *)[subviewArray objectAtIndex:2];
[messageLB setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelBT = (UIButton *)[subviewArray objectAtIndex:3];
[cancelBT setFrame:CGRectMake(10, 130, 100, 42)];
UIButton *okBT = (UIButton *)[subviewArray objectAtIndex:4];
[okBT setFrame:CGRectMake(194, 130, 80, 42)];
UIButton *searchBT = (UIButton *)[subviewArray objectAtIndex:5];
[searchBT setFrame:CGRectMake(112, 130, 80, 42)];
UITextField *plateTF = (UITextField *)[subviewArray objectAtIndex:6];
[plateTF setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
FYI [subviewArray objectAtIndex:1] is for title of alertview.

How to set height and width of a UIAlertView?

I have a UIAlertView with an image and a large button.
The problem is that the default UIAlertView is a very small size. It's image cannot be seen properly.
So, I want to increase the height and width of the UIAlertView. In other words, I want to create a custom UIAlertView. What would be the way to do that?
Thanks.
I am sending you my code, I am showing a TableView in AlertView, perhaps it will help you.
in header file paste this code.
#import <UIKit/UIKit.h>
#interface aaViewController : UIViewController <UIAlertViewDelegate, UITableViewDelegate, UITableViewDataSource>{
UITextField *textfield;
UITableView *tableView1;
NSMutableArray *_data;
}
#property (nonatomic, retain) NSMutableArray *_data;
- (void) showAlertView;
- (void) doAlertViewWithTextView;
- (void) doAlertViewWithTableView;
#end
and in your imlpementation(.m) file paste this code.
#import "aaViewController.h"
#implementation aaViewController
#synthesize _data;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self._data = [NSMutableArray arrayWithObjects:#"Najeeb", #"Furqan", #"Khalid", nil];
[self doAlertViewWithTableView];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (void) doAlertViewWithTextView {
UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 0, 300, 550)];
alert.title = #"Textview";
alert.message = #"I am doing cool stuff\n\n\n";
alert.delegate = self;
[alert addButtonWithTitle:#"Cancel"];
[alert addButtonWithTitle:#"OK"];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(12, 90, 260, 200)];
textView.text = #"This is what i am trying to add in alertView.\nHappy New Year Farmers! The new Winter Fantasy Limited Edition Items have arrived! Enchant your orchard with a Icy Peach Tree, and be the first farmer among your friends to have the Frosty Fairy Horse. Don't forget that the Mystery Game has been refreshed with a new Winter Fantasy Animal theme! ";
textView.keyboardAppearance = UIKeyboardAppearanceAlert;
[alert addSubview:textView];
[textView release];
[alert show];
[alert release];
}
- (void) doAlertViewWithTableView {
NSLog(#"Now play with TableView \n%#", self._data);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Table View" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
tableView1 = [[[UITableView alloc] initWithFrame:CGRectMake(10, 40, 264, 200) style:UITableViewStyleGrouped] autorelease];
tableView1.dataSource = self;
tableView1.delegate = self;
[alert addSubview:tableView1];
[alert show];
[alert release];
}
//#define kTag_EnterNameAlert 1
//#define kTag_NameEmtryField 100
- (void) showAlertView {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Congratulations!"
message:#"You earned a top score! Enter your name:\n\n"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
//alert.tag = kTag_EnterNameAlert;
CGRect entryFieldRect = CGRectZero;
if( UIDeviceOrientationIsPortrait( [UIApplication sharedApplication].statusBarOrientation ) ) {
entryFieldRect = CGRectMake(12, 90, 260, 25);
}
else {
entryFieldRect = CGRectMake(12, 72, 260, 25);
}
textfield = [[UITextField alloc] initWithFrame:entryFieldRect];
//textfield.tag = kTag_NameEmtryField;
textfield.backgroundColor = [UIColor whiteColor];
textfield.keyboardType = UIKeyboardTypeAlphabet;
textfield.keyboardAppearance = UIKeyboardAppearanceAlert;
textfield.autocorrectionType = UITextAutocorrectionTypeNo;
textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
[alert addSubview:textfield];
[textfield becomeFirstResponder];
[textfield release];
[alert show];
[alert release];
}
# pragma -
# pragma alertView frame Methods
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(#"name:%# buttonID:%d",textfield.text,buttonIndex);
if (buttonIndex == 1) {
[self doAlertViewWithWebView];
}
else {
NSLog(#"%#",alertView.message);
}
}
// to set the alertView frame size.
- (void)willPresentAlertView:(UIAlertView *)alertView {
[alertView setFrame:CGRectMake(10, 100, 300, 320)];
for ( UIView *views in [alertView subviews]) {
NSLog(#"%#",views);
if (views.tag == 1 || views.tag == 2) {
[views setFrame:CGRectMake(views.frame.origin.x, views.frame.origin.y+200, views.frame.size.width, views.frame.size.height)];
}
}
}
# pragma -
#pragma mark TableView Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 1) {
return [_data count];
}
else
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* const SwitchCellID = #"SwitchCell";
UITableViewCell* aCell = [tableView dequeueReusableCellWithIdentifier:SwitchCellID];
if( aCell == nil ) {
aCell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SwitchCellID] autorelease];
aCell.textLabel.text = [NSString stringWithFormat:#"Option %d", [indexPath row] + 1];
aCell.selectionStyle = UITableViewCellSelectionStyleNone;
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
switchView.tag = [indexPath row]+1;
aCell.accessoryView = switchView;
[switchView setOn:YES animated:NO];
[switchView addTarget:self action:#selector(soundSwitched:) forControlEvents:UIControlEventValueChanged];
[switchView release];
}
return aCell;
}
- (void) soundSwitched:(UISwitch*) switchView {
if (!switchView.on) {
NSLog(#"chal bhag %d", switchView.tag);
}
}
#end
Note: In your AppDelegate add as subView to this.

UIAlertView - retrieve textfield value from textfield added via code

Here is the code I have to create an UIAlertView with a textbox.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Enter A Username Here" message:#"this gets covered!"
delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:#"OK!", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);
[alert setTransform:myTransform];
alert.tag = kAlertSaveScore;
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert show];
[alert release];
[myTextField release];
My question is, how do I get the value from the textfield in:
- (void) alertView:(UIAlertView *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
}
I know I can get the standard stuff for the alertview such as actionSheet.tag and such, but how would I get the above created textfield?
#interface MyClass {
UITextField *alertTextField;
}
#end
And instead of declaring it locally, just use that.
//...
alertTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
//...
- (void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *text = alertTextField.text;
alertTextField = nil;
}
Just give it a tag, and find it using the tag later. So, using your code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Enter A Username Here" message:#"this gets covered!"
delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:#"OK!", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);
[alert setTransform:myTransform];
alert.tag = kAlertSaveScore;
// Give the text field some unique tag
[myTextField setTag:10250];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert show];
[alert release];
[myTextField release];
Then, in the call-back, wherever that happens to be and without having to worry about memory management or state management of the text field:
- (void) alertView:(UIAlertView *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Get the field you added to the alert view earlier (you should also
// probably validate that this field is there and that it is a UITextField but...)
UITextField* myField = (UITextField*)[actionSheet viewWithTag:10250];
NSLog(#"Entered text: %#", [myField text]);
}

AlertView with TextField Problem

Hey guys, I'm having trouble obtaining the value/text from a AlertView TextField. Maybe someone can look at my code and see what I'm doing wrong. Every time I press OK, the label get's a (null) value. I must be missing something here.
TextFieldINAlertViewController.h
#import <UIKit/UIKit.h>
#interface TextFieldInAlertViewController : UIViewController {
UITextField *myTextField;
IBOutlet UILabel *labelView;
NSString *FieldStr1;
}
#property (nonatomic, copy) NSString *FieldStr1;
#end
TextFieldInAlertViewController.m
#import "TextFieldInAlertViewController.h"
#implementation TextFieldInAlertViewController
#synthesize FieldStr1;
- (void)viewDidLoad {
[super viewDidLoad];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Enter Name Here" message:#"blank" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:#"OK!", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);
[alert setTransform:myTransform];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert show];
[alert release];
}
-(void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)index
{
if (index == 0){
return;
}
if (index == 1){
FieldStr1 = myTextField.text;
labelView.text = [NSString stringWithFormat:#"%#" , FieldStr1 ];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
#end
myTextField is a local variable in viewDidLoad, but it's also a member variable in your class. Get rid of the local declaration, and you should be fine. Also, I'd move this code to viewDidAppear:, rather than viewDidLoad.
Since iOS5 you can use property on the alertView which is a much simplier way to add a textField.
If you want to add a TextField to an UIAlertView, you can use this property (alertViewStyle) for UIAlertView:
- (void)showAlert{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Done" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
((UITextField *) [alertView textFieldAtIndex:0]).text = #"Default Value";
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(#"%#", [alertView textFieldAtIndex:0].text);
}
Check UIAlertView reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
Hugues