iOS开发学习之#提醒处理#(2)响应动作表单
来源:程序员人生 发布时间:2014-12-13 08:58:10 阅读次数:2831次
在动作表单中我们用很多按钮实现,在这里我们用到了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 = @"春子(はるこ)さんの家は日本
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
------分隔线----------------------------
------分隔线----------------------------