ios - 如何确定 UIButton 被按下?

标签 ios arrays swift uibutton

我正在尝试为我的 child 制作一个简单的应用程序。

下一步是

  1. 检测按下了什么UIButton
  2. 将特定数组的值赋给一个空数组 按钮

我暂时有两个按钮(总共会有20+)

@IBAction func tapLA(sender: UIButton) {
}

@IBAction func tapLB(sender: UIButton) {
}

它们都与具有图像数组的 PageViewController 相连

// the array
private var contentImages = ["",
                             "",
                             "",
                             ""]

//the array of gallery images lettera A
private let contentImagesA = ["letteraA",
                              "ape",
                              "albero",
                              "arcobaleno"]


// the array of gallery immages lettera B
private let contentImagesB = ["letteraB",
                              "barca",
                              "balena",
                              "banana"]

我需要根据点击的按钮显示不同的数组,但我不知道该怎么做。 简而言之应该是:

如果按钮 A 被按下,显示数组 A 的图像

如果按钮 B 被按下,显示数组 B 的图像。

最佳答案

当按钮被选中时运行加载图片的方法

@IBAction func tapLA(sender: UIButton) {
    openPicturesFrom(contentImagesA)
}

func openPicturesFrom(arr: Array) {
    //here you have array and you can start opening pictures
}

关于ios - 如何确定 UIButton 被按下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39466855/

相关文章:

ios - 创建具有默认行为的更可重用的 UITableView 子类

iphone - 动态地将 UITableView 分成任意部分?

ios - 多个 RESTful Web 服务调用与 MySQL JOIN

javascript - 用 JavaScript 将字符串转换为数组?

java - 数组中缺少 return 语句错误

objective-c - 感叹号对于快速初始化程序意味着什么?

ios - 为什么我的图像没有显示在 UIImageView 中?

ios - 如何在 Windows 上使用 SwiftUI 制作 iOS 应用程序?

ios - 如何高效过滤约20万个NSDictionaries的NSArray?

javascript - 通过编辑文件来通过 Node.js 更改 JSON 中的对象值