iOS開發學習之#提醒處理#(2)響應動作表單

來源:互聯網
上載者:User

iOS開發學習之#提醒處理#(2)響應動作表單

在動作表單中我們用很多按鈕實現,在這裡我們用到了UIActionsheetDelegate協議中的actionSheet:clickedButtonAtIndex:方法實現,其文法形式如下:

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

其中,(UIActionSheet*)actionSheet 用來指定動作表單中包含的按鈕,(NSInteger)buttonIndex用來指定被點擊按鈕的索引


核心代碼如下:

ViewController.h

#import @interface ViewController : UIViewController{    IBOutlet UITextView *tv;    IBOutlet UILabel *l;}- (IBAction)aa:(id)sender;@end


ViewController.m

- (IBAction)aa:(id)sender {    UIActionSheet *ac = [[UIActionSheet alloc]initWithTitle:@"語言選擇" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:@"中文" otherButtonTitles:@"英文",@"日語", nil];    [ac showInView:self.view];}- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{    NSString *t = [actionSheet buttonTitleAtIndex:buttonIndex];    if ([t isEqualToString:@"中文"]) {        tv.text = @"從前有個可愛的小姑娘,誰見了都喜歡,但最喜歡她的是她的外婆,簡直是她要什麼就給她什麼。一次,外婆送給小姑娘一頂用絲絨做的小紅帽,戴在她的頭上正好合適。從此,姑娘再也不願意戴任何別的帽子,於是大家便叫她“小紅帽”。";        l.text = @"小紅帽";    }else if ([t isEqualToString:@"英文"]){        tv.text = @"Once there was a little girl, she always wore a red hat, so everybody called her the Little Red Hat.One day little red hat’s mother said to her,“Little red hat, your grandma is ill, please go and see her, give her these cakes. Remember you must walk along the main road.” “Yes, mum I remember.”She took the cakes and made her way to her grandma’s. She walked and walked. Suddenly she came across a big grey wolf. ";         l.text = @"Litle Red Riding Hood";    }else if ([t isEqualToString:@"日語"]){        tv.text = @"春子(はるこ)さんの家は日本橋(にほんばし)にはありません。淺草(あさくさ)の近(ちか)くにあります。雷門(かみなりもん)はその家の西側(にしがわ)にあります。家族(かぞく)は三人です。両親(りょうしん)と彼女です。";        l.text = @"春子(はるこ)";    }}


聯繫我們

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