可能重复:
warning: 'UIAlertView' may not respond to '-addTextFieldWithValue:label:'
我使用下面的代码在AlertView中放置文本字段,它会发出一个警告,例如“UIAlertView可能无法响应 - addTextFieldWithValue:label:”& “UIAlertView可能无法响应 - 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];
请帮忙!
答案 0 :(得分:0)
这些方法不像addTextFieldWithValue
中的UIAlertView
。
答案 1 :(得分:0)
uialertview没有方法“addTextFieldWithValue”
如果您需要修改提醒视图,请查看我的博客 - http://www.makebetterthings.com/blogs/iphone/add-uitextfield-in-uialertview/
答案 2 :(得分:0)
[alert addTextFieldWithValue:@"" label:@"Email"];
是私人API。我的应用程序因使用此功能而被拒绝。
使用此
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];
答案 3 :(得分:0)
**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]];
}
}