警告框和動作表(IOS開發)

來源:互聯網
上載者:User

標籤:des   style   blog   io   ar   os   使用   div   on   

警告框(AlertView)時模態的,不關閉它就不能做其它事情,所以不是下面幾種情況不應該隨便使用。

1、應用不能繼續執行。

如記憶體不足,沒有網路。一般僅僅須要一個button。

2、詢問還有一個解決方式。

不能執行時,詢問能否夠用3G網路。

3、詢問對操作的授權。

涉及到訪問隱私資訊的時候,須要使用者授權,如位置、相冊等。


動作表(ActionSheet)能夠給使用者提供多個選擇。能夠利用它將某個圖片發給新浪微博或者Facebook平台。

/ 實現UIAlertViewDelegate// 這個託付事實上沒實用到,就當練練手,由於警告表單有兩個按鈕索引// No為0,Yes為1-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    NSLog(@"buttonIndex = %li", (long)buttonIndex);}// 實現UIActionSheetDelegate// 這個託付也沒有實際意義,就是在輸出命令表單輸出按下的索引數,以實現響應- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{    NSLog(@"buttonIndex = %li", (long)buttonIndex);}- (IBAction)testAlertView:(id)sender {    // 警告框在上文已敘述    // delegate 參數用於設定該警告表單的託付對象    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"                                                message: @"Alert text goes here"                                                delegate:self cancelButtonTitle:@"No"                                              otherButtonTitles:@"Yes",                              nil];    [alertView show];    }- (IBAction)testActionSheet:(id)sender {    // cancelButtonTitle 設定取消標題    // destructiveButtonTile 設定破壞型按鈕,僅僅能有一個在最上面    UIActionSheet *actionSheet = [[UIActionSheet alloc]                                  initWithTitle:nil                                  delegate:self                                  cancelButtonTitle:@"取消"destructiveButtonTitle:@"破壞性按鈕"                                  otherButtonTitles:@"新浪微博", nil];    // 設定為自己主動樣式    actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;    [actionSheet showInView:self.view];}


警告框和動作表(IOS開發)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.