ios - 通过传入数组而不是 varlist 创建 UIActionSheet 'otherButtons'

标签 ios iphone uialertview uiactionsheet

我有一个字符串数组,我想将其用于 UIActionSheet 上的按钮标题。不幸的是,方法调用中的 otherButtonTitles: 参数采用可变长度的字符串列表,而不是数组。

那么如何将这些标题传递到 UIActionSheet 中呢?我看到建议的解决方法是将 nil 传递给 otherButtonTitles:,然后使用 addButtonWithTitle: 单独指定按钮标题。但这有将“取消”按钮移动到 UIActionSheet 上的第一个位置而不是最后一个的问题;我希望它是最后一个。

有没有办法 1) 传递一个数组来代替字符串变量列表,或者 2) 将取消按钮移动到 UIActionSheet 的底部?

谢谢。

最佳答案

我让这个工作(你只需要,用一个普通的按钮就可以了,只需在之后添加它:

NSArray *array = @[@"1st Button",@"2nd Button",@"3rd Button",@"4th Button"];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title Here"
                                                             delegate:self
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];

    // ObjC Fast Enumeration
    for (NSString *title in array) {
        [actionSheet addButtonWithTitle:title];
    }

    actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];

    [actionSheet showInView:self.view];

关于ios - 通过传入数组而不是 varlist 创建 UIActionSheet 'otherButtons',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2384044/

相关文章:

ios - UIWebView内容如何保存离线显示?

iphone - 进入后台时如何争取时间完全关闭 UIAlertView?

iphone - 上网查ios应用

ios - 将 iOS 应用程序重新连接到配对的蓝牙设备?

ios - 从 NSURL 获取 MBProgressHUD 的进度

ios - 无法从 swift ios 中的一段 tableview 中删除单元格

swift - 从当前模式的委托(delegate)中呈现 UIAlertView

ios - 带有 UIActivity 指示器的 UIAlert View - 仅显示事件一次

ios - 如何让用户复制 UIAlertView 的描述?

iphone - 使用 Parse 从应用程序内打开和关闭推送通知