標籤:
【轉】
alertView 有兩個button時,一般預設使左邊的是取消,右邊的是確認。蘋果習慣~
alertView 的屬性是可以設定的。 [AlertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput]; <
UIAlertView *alertView = [UIAlertView alloc] initWithTitle:@"DefaultAlertView"message:@"Defalut"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil]; <
顯示alertView [alertView show]; <
代理方法
按index索引點擊事件,index從0開始 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 這個方法在動畫結束和視圖隱藏之後調用 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 這個方法在動畫開始和視圖隱藏之前調用 - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex 在視圖將要被取消之前 - (void)alertViewCancel:(UIAlertView *)alertView 在視圖提交給使用者以後調用 - (void)didPresentAlertView:(UIAlertView *)alertView
設定yes / no 將會設定alertView 的第一個otherButton的enable屬性 - (BOOL)alertViewShouldEnableFirstOtherButton(UIAlertView *)alertView
這六個delegate 方法調用的順序依次是 alertViewShouldEnableFirstOtherButton willPresentAlertView didPresentAlertView clickedButtonAtIndex willDismissWithButtonIndex(如果會觸發視圖取消,則會調用alertViewCancel) didDismissWithButtonIndex ios4.0以後 alertView不會自動隨著程式轉向後台而移除alertView屬性1.alertViewStyle:只彈資訊和按鈕 UIAlertViewStyleDefault 有一個textfield加密框 UIAlertViewStyleSecureTextInput 有一個不加密的 textfieldUIAlertViewStylePlainTextInput 有兩個textfield, Login和passwordUIAlertViewStyleLoginAndPasswordInput 只要有textfield就可以用textfieldAtIndex來捕獲並進行相應的操作例如換鍵盤類型 2.cancelButtonIndex 開始是0,如果沒有設定cancel button 則是-1 3.delegate 如果沒有設定則是nil 4.firstOtherButtonIndex 從0開始,如果沒設定則是-1,而且沒被設定則會被忽略 5.message 訊息 6.numberOfButtons 唯讀 alertView中的按鈕數量 7.title 標題 8.visible 唯讀 如果是yes 表示被顯示 執行個體方法傳回值是增加的Button的index - (NSInteger)addButtonWithTitle:(NSString *)title 輸入buttonIndex 返回button的標題 - (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex程式自動完成點擊buttonIndex的button 並dismiss 整個alertView的操作 - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated要顯示必須要調用這個alertview才會顯示 - (void)show 傳回值是textfield - (UITextField *)textfieldAtIndex:(NSInteger)textfieldIndexUIAlertViewStyleDefault 沒有UIAlertViewStyleSecureInput textfieldIndex 只有一個為0UIAlertViewStylePlainInput textfieldIndex 只有一個為0UIAlertViewStyleLoginAndPasswordInput textfieldIndex有兩個 0 1
IOS學習筆記(四)AlertView