IOS筆記之UIKit_UIAlertView、UIActionSheet

來源:互聯網
上載者:User

標籤:des   style   io   color   os   sp   on   log   bs   

//首先必須繼承協議

@interface TRViewController : UIViewController<UIAlertViewDelegate,UIActionSheetDelegate>

 

 

//UIAlertView功能實現

- (IBAction)clicked:(id)sender {

    UIButton *btn = sender;

     //設定tag值

    if (btn.tag==0) {

        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];

         // 設定AlertView樣式

        [alertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];

        //把alertView裡面的TF取出來

          UITextField *nameTF = [alertView textFieldAtIndex:0];

          UITextField *pwTF = [alertView textFieldAtIndex:1];

          nameTF.text = @"haha";

          pwTF.text = @"adfadsf";

 

        //彈窗顯示

        [alertView show];

       }else{

      //UIActionSheet初始化

         UIActionSheet *as = [[UIActionSheet alloc]initWithTitle:@"Title" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"destructive" otherButtonTitles:@"呵呵", nil];

        [as showInView:self.view];

    }

}

 

    //AlertView點擊事件

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

    NSLog(@"%ld",(long)buttonIndex);

   //第一個按鈕

        if (buttonIndex==1) {//確定

        UITextField *nameTF = [alertView textFieldAtIndex:0];

        UITextField *pwTF = [alertView textFieldAtIndex:1];

        NSLog(@"%@  %@",nameTF.text,pwTF.text);

    }else{//取消

    }

}

//ActionSheet點擊事件

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    NSLog(@"%ld",(long)buttonIndex);

}

IOS筆記之UIKit_UIAlertView、UIActionSheet

聯繫我們

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