【问题标题】:UIActionsheet not displaying all buttons on iPads running iOS7UIActionsheet 未在运行 iOS7 的 iPad 上显示所有按钮
【发布时间】:2015-01-19 12:40:44
【问题描述】:

UIActionSheet 的实例无法在运行 iOS7 的 iPad 上正确显示。出于某种原因,它们会显示取消按钮并保留最后一个按钮。相同的代码在 iOS8 上运行良好。

您可能希望取消按钮被忽略,因为点击屏幕上的其他地方会关闭操作表。有谁知道为什么会这样?

在这两种情况下使用完全相同的代码:

// Create UIActionSheet    
let mapOptions = UIActionSheet(title: "Select map type", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Standard", "Hybrid", "Satellite")

// Display from bar button
mapOptions.showFromBarButtonItem(self.mapTypeButton, animated: true)

【问题讨论】:

    标签: ios ipad ios7 swift uiactionsheet


    【解决方案1】:

    我能够通过避免使用默认的 UIActionSheet 构造函数并单独添加按钮来解决问题。这 - 并确保最后添加取消按钮 - 解决了问题。

    // Create the UIActionSheet
    var mapOptions = UIActionSheet()
    mapOptions.title = "Select map type"
    mapOptions.addButtonWithTitle("Standard")
    mapOptions.addButtonWithTitle("Hybrid")
    mapOptions.addButtonWithTitle("Satellite")
    
    // Add a cancel button, and set the button index at the same time
    mapOptions.cancelButtonIndex = mapOptions.addButtonWithTitle("Cancel")
    mapOptions.delegate = self
    
    // Display the action sheet
    mapOptions.showFromBarButtonItem(self.mapTypeButton, animated: true)
    

    【讨论】:

      【解决方案2】:

      我在使用 Swift 时遇到了同样的问题。你的回答救了我。 我发现你仍然可以使用这个 init 方法(带有取消按钮 nil)来让你的代码更简洁。

      let mapOptions = UIActionSheet(title: "Select map type", delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil, otherButtonTitles: "Standard", "Hybrid", "Satellite")
      

      然后用你提供的那一行

      mapOptions.cancelButtonIndex = mapOptions.addButtonWithTitle("Cancel")
      

      (我没有足够的声誉来添加评论,所以请写在这里。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 2013-10-30
        相关资源
        最近更新 更多