2012年8月28日 星期二

[iOS] 內建 UIAlertView 顯示輸入框的方法


常常使用 UIAlertView 來顯示一些告知使用者訊息的功能,但在登入或需要使用者輸入一些欄位時(ex:密碼)可用以下的方法來呈現:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
UITextField *textField = [alertView textFieldAtIndex:0];
[alertView show];

紅色字的部份可參考以下的列舉使用。

typedef enum {
    UIAlertViewStyleDefault = 0,
    UIAlertViewStyleSecureTextInput,
    UIAlertViewStylePlainTextInput,
    UIAlertViewStyleLoginAndPasswordInput
} UIAlertViewStyle;

沒有留言:

張貼留言