iOS開發學習之#提醒處理#(2)響應動作表單
來源:程序員人生 發布時間:2014-12-13 08:58:10 閱讀次數:2991次
在動作表單中我們用很多按鈕實現,在這里我們用到了UIActionsheetDelegate協議中的actionSheet:clickedButtonAtIndex:方法實現,其語法情勢以下:
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
其中,(UIActionSheet*)actionSheet 用來指定動作表單中包括的按鈕,(NSInteger)buttonIndex用來指定被點擊按鈕的索引
核心代碼以下:
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIActionSheetDelegate>{
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 = @"從前有個可愛的小姑娘,誰見了都喜歡,但最喜歡她的是她的外婆,簡直是她要甚么就給她甚么。1次,外婆送給小姑娘1中用絲絨做的小紅帽,戴在她的頭上正好適合。從此,姑娘不再愿意戴任何別的帽子,因而大家便叫她“小紅帽”。";
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 = @"春子(はるこ)さんの家は日本
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
------分隔線----------------------------
------分隔線----------------------------