UIAlertView

使用控制器和視圖

Model 應用程序的核心 負責計算與創建一個虛擬世界,它不依靠ViewController就能存在。(一個沒有外觀接口的應用程序)

ControllerXcode通常是指View controller。可以把它想成一座ModelView之間的橋樑。

View則是一個讓用戶可以與程序溝通的窗口,大部分情況下,View都是用來顯示Model提供的數據,除此之外也負責處理與用戶的互動。用戶都是透過View與應用程序間的互動,而Controller則負責捕捉互動訊息並傳送給Model


使用UIAlertView顯示提示

UIAlertView *alertView = [ [ UIAlertView

 alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];

[alertView show];

UIAlertView 有提供一個類型爲UIAlertViewStyle的屬性

tyledef enum{

    UIAlertViewStyleDefault = 0,//默認樣式

    UIAlertViewStyleSecureTextInput,//這個樣式中,提示視圖會包含一個安全加密的文字欄位。

    UIAlertViewStylePlainTextInput,//在這種樣式中,提示視圖會顯示一個可見的文字欄位,一般來說使用這種樣式來要求用戶輸入一些信息,例如電話號碼。

    UIAlertViewStyleLoginAndPasswordInput//在這個樣式中,提示視圖會顯示兩個文本欄位,一個是可見的用戶名稱欄位,另一個是加密 密碼欄位。

}UIAlertViewStyle;

若希望從提示視圖得到用戶操作通知,就必須制定一個委託對象,委託對象符合UIAlertViewDelegate協定。

alertViewclickedButtonAtIndex 這個方法可以得到用戶在提示視圖上所按下的按鈕。

-(NSString *)yesButtonTitle{

    return @"Yes";

}

-(NSString *)noButtonTitle{

    return @"No";

}

[ [ UIAlertView

 alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:[self noButtonTitle] otherButtonTitles:[self yesButtonTitle],nil];

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    NSString *buttonTitle = [alertView buttonTItleAtIndex:buttonIndex];

if([buttonTitle isEqualToString:[self yesButtonTitle]]){

     YES;

    }else if([buttonTitle isEqualToString:[self noButtonTitle]]){

      NO;

    }

}

發佈了190 篇原創文章 · 獲贊 0 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章