开发者

Warning on Alertview [duplicate]

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]];
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜