`

IOS之操作表ActionSheet(免Delegate)

 
阅读更多

        接下来的操作,也是避免了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];
}

 

 

  • 大小: 24.2 KB
分享到:
评论

相关推荐

    ios-ActionSheet.zip

    在iOS开发中,ActionSheet是一种常见的用户界面元素,它用于向用户提供一组操作选项,通常在用户需要做出选择或执行特定任务时出现。ActionSheet的设计遵循苹果的Human Interface Guidelines(HIG),旨在提供清晰、...

    UIActionSheet

    let actionSheet = UIActionSheet(title: "操作选择", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "操作1", "操作2") ``` 在这个例子中,"操作选择"是...

    iOS 系统三种弹框的封装

    要创建一个UIAlertController,你需要定义其样式(警告或操作表)、标题、消息,以及任何按钮: ```swift let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert) ...

    adaptive_dialog:根据平台自适应地显示警报对话框或模式操作表

    根据平台自适应地显示警报对话框或模式操作表。 便捷的包装器。 的iOS 安卓 便捷的包装器。 的iOS 安卓 显示。 对于Cupertino,请改用ActionSheet。 的iOS 安卓 的iOS 安卓 的iOS 安卓 显示文本输入...

    ios-下拉列表.zip

    在iOS中,通常通过UIAlertController的 preferredStyle设置为`.actionSheet`来创建。Action Sheet可以包含一个或多个按钮,当用户点击某个按钮时,会触发相应的回调。 ### 三、列表优化策略 根据描述“对之前列表...

    ios需用单词

    如弹出框ActionSheet:动作表,另一种弹出视图Slider:滑块DatePicker:日期选择器Notification:通知,用于在应用程序的不同部分之间传递信息Delegate:代理,实现特定功能的协议实现方式Notification Center:通知中心,...

    可自定义外观的FMActionSheet

    FMActionSheet是一款适用于iOS开发的开源库,它允许开发者自定义外观,以创建美观且功能丰富的操作表视图。在iOS应用中,操作表视图(Action Sheet)通常用于向用户展示一组选择,如分享、删除或取消等操作。...

    UIActionSheet定制按钮的例子

    let actionSheet = UIActionSheet(title: "选择操作", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: "删除", otherButtonTitles: "保存") ``` 这里的`title`是整个动作表的标题,`delegate...

Global site tag (gtag.js) - Google Analytics