1

in my application i was using UIAlertView for login, it contains TextFields, its working perfectly, but i'm getting a warning when i compile the code, i'm using iphone SDK 3.0

code :

loginAlert = [[UIAlertView alloc] initWithTitle:@"Enter the User Name and Password" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Login", nil];
  
[loginAlert addTextFieldWithValue:appDelegate.userName label:@"UserName"];

warning: 'UIAlertView' may not respond to '-addTextFieldWithValue:label:'



txfUserName = [loginAlert textFieldAtIndex:0];

warning: 'UIAlertView' may not respond to '-textFieldAtIndex:'

Community
  • 1
  • 1
shinto Joseph
  • 1,039
  • 3
  • 16
  • 27

3 Answers3

3

This method is private, you should not use it (your app will be rejected). Maybe they removed or renamed it in the latest SDK. For an alternative, see

http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html

fraca7
  • 1,178
  • 5
  • 11
2
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:testTextField];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
[myAlertView setTransform:myTransform];
[myAlertView show];
[myAlertView release];

all credits to: http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html

Lorenzo Boccaccia
  • 6,041
  • 2
  • 19
  • 29
  • Its working, but there is an initial delay, not as perfect as the private method, thank you for the valuable information – shinto Joseph Feb 26 '10 at 04:37
  • you may create the view on the containing UIViewController class initialization and release it when the view unloads, so the delay is masked by the transition. – Lorenzo Boccaccia Feb 26 '10 at 14:01
0

You can use http://github.com/enormego/EGOTextFieldAlertView. It gives you those private methods, in a subclass of UIAlertView. This way you don't have to change your code at all.

MrMage
  • 7,282
  • 2
  • 41
  • 71
  • 1
    Apple uses an automated static analyzer; the app will still be rejected because the method is named the same, I think. – fraca7 Feb 19 '10 at 11:16
  • As far as I know, this is not the case: to my knowledge, enormego (the creator of that class) did publish some apps with `EGOTextFieldAlertView`. – MrMage Feb 19 '10 at 15:18
  • Strange, I've heard of apps rejected because of a private method name. Good to know. – fraca7 Feb 22 '10 at 08:22
  • EGOTextFieldAlertView changes the names of the methods it has to make them different from the private methods – Beta Dec 14 '12 at 01:00