2011-05-19 124 views
1

可能重複:
warning: 'UIAlertView' may not respond to '-addTextFieldWithValue:label:'警告上Alertview

我使用下面的AlertView放文本框代碼,它給像「UIAlertView中可能沒有響應的警告 - addTextFieldWithValue:標籤: 「&」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

這些在UIAlertView中沒有像addTextFieldWithValue這樣的方法。

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

什麼是你想用這樣說? – Saurabh 2011-05-19 08:11:33