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

來源:互聯網
上載者:User

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

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

1、應用不能繼續運行。

如記憶體不足,沒有網路。一般只需要一個按鈕。

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];}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.