开发者

Need to get rid of some warnings

开发者 https://www.devze.com 2023-02-18 01:49 出处:网络
I have a alert view that has a text field inside of it. Here is the code: UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@\"Password\" mess开发者_C百科age:nil delegate:self cancelButtonTit

I have a alert view that has a text field inside of it. Here is the code:

UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Password" mess开发者_C百科age:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Enter", nil];
[myAlert addTextFieldWithValue:nil label:@"Type Password"];
[[myAlert textField] setSecureTextEntry:YES];
[[myAlert textField] setDelegate:self];
[[myAlert textField] setTextAlignment:UITextAlignmentCenter];
[[myAlert textField] becomeFirstResponder];
[myAlert show];
[myAlert release];
myAlert = nil;

I get 4 warnings, each on the lines that include [[myAlert textField]. The warnings I get are "Method -addTextFieldWithValue:label: not found (return type defaults to 'id')" and "Method '-textField' not found (return type defaults to 'id')." What should I do to fix these? Is there a better way to display a text field within an alert view without any warnings?


The reason for your warnings is that the UIAlertView class doesn't have any such methods as addTextFieldWithValue or textField.

Generally speaking, alert views are not intended for input, other than allowing a choice between a few basic options ("yes/no", "ok/cancel", etc). If you need a user to type in a password, your text field should be somewhere on a regular view. It is for exactly this reason the kind of methods you are after are not implemented in UIAlertView.

For reference: UIAlertView

0

精彩评论

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