iphone - 为 iPhone 和 iPad 使用不同的 Storyboard时如何为按钮设置 Action ?

标签 iphone swift xcode ipad storyboard

我想为 ipad 和 iphone 使用不同的 Storyboard。我按照这个 tutorial 成功地做到了.

但我想知道如何在 iPad 和 iPhone 中为 Button 调用相同的操作。

最佳答案

创建一个 IBAction 并在 Storyboard中为其分配 button,现在如果你想区分它是从 iphone 调用还是从 ipad 您可以在 IBAction 中为其添加条件。

@IBAction func buttonClick(sender: UIButton) {
    if (UIDevice.currentDevice().userInterfaceIdiom == .Pad) {
         // It is from iPad
    }
    else { 
         // It is from iPhone
    }   
}

关于iphone - 为 iPhone 和 iPad 使用不同的 Storyboard时如何为按钮设置 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38865581/

相关文章:

ios - 从 View Controller 对负 y 原点进行动画处理会破坏约束

xcode - High Sierra 上的 Home-brew 安装失败

ios - iOS 设备的总 RAM 大小

NSObject+KVO.swift 文件中的 Swift Bond 编译错误

iphone - 在 App Purchase 中没有返回任何响应

ios - NSLayoutConstraint 将 View 固定到父 View 的底部边缘

swift - 展开后 TableView 消失

objective-c - IBOutletCollection 在 Interface Builder 中设置排序

iphone - 流式获取数据 - NSInputStream

ios - 两分钟gps开启后,为什么设备会停止在iOS上接收位置信息?