您的位置:首页 > 移动开发 > IOS开发

IOS之操作表ActionSheet(免Delegate)

2014-01-12 13:49 405 查看

        接下来的操作,也是避免了Delegate的写法,方便对不同ActionSheet的分层操作。

1.添加头文件。文件可在附件下载。具体资料请参考:https://github.com/emenegro/action-sheet-blocks#readme

#include "UIActionSheet+Blocks.h"

 2.添加如下的方法。(自定义UIButton的单击触发事件)

- (IBAction)showActionSheet:(UIButton *)sender forEvent:(UIEvent *)event {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Test"
delegate:nil // Can be another value but will be overridden when showing with handler.
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete"
otherButtonTitles:@"Option 1", @"Option 2", nil];
[sheet showInView:self.view
handler:^(UIActionSheet *actionSheet, NSInteger buttonIndex) {
if (buttonIndex == [actionSheet cancelButtonIndex]) {
NSLog(@"Cancel button index tapped");
} else if (buttonIndex == [actionSheet destructiveButtonIndex]) {
NSLog(@"Destructive button index tapped");
} else  {
NSLog(@"Button %i tapped", buttonIndex);
}
}];
sheet.actionSheetStyle =  UIActionSheetStyleAutomatic;
[sheet showInView:self.view];
}

 

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: