iOS开发学习之#提醒处理#(2)响应动作表单

在动作表单中我们用很多按钮实现,在这里我们用到了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 = @"从前有个可爱的小姑娘,谁见了都喜欢,但最喜欢她的是她的外婆,简直是她要什么就给她什么。一次,外婆送给小姑娘一顶用丝绒做的小红帽,戴在她的头上正好合适。从此,姑娘再也不愿意戴任何别的帽子,于是大家便叫她“小红帽”。";
        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 = @"春子(はるこ)";
    }
}

            
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值