我有许多按钮都具有相同的动作,所以我使用了一个集合View
@IBOutlet var playerButtons: [UIButton]!
我希望使用选择器视图允许我选择一个名称,然后设置按钮的标题,但是我似乎无法找到如何在集合视图中实现这一点。
我正在尝试使用docent的功能似乎可以工作
open func setTitle(_ title: String?, for state: UIControlState)
我的完整代码是
import UIKit
import Firebase
class TeamSelection: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
//IBOutlets Collection for Player Names
@IBOutlet var playerButtons: [UIButton]!
@IBOutlet var Player: [UIView]!
@IBOutlet weak var homeTeamLabel: UILabel!
@IBOutlet weak var pickerView: UIPickerView!
var player = [Players]()
var club: Clubs!
var clubName = String()
var playerFirstName = String()
var playerLastName = String()
// Will be removed and Firebase used in place
var players = ["player 1", "player 2", "player 3", "and so on"]
override func viewDidLoad() {
super.viewDidLoad()
pickerView.dataSource = self
pickerView.delegate = self
CLUB_KEY = ""
CLUB_KEY = club.clubKey
self.navigationItem.title = club.clubName
DataService.ds.REF_PLAYERS.queryOrdered(byChild: "clubKey").queryEqual(toValue: club.clubKey).observe(.value, with: { (snapshot) in
print("PLAYERS_COUNT: \(snapshot.childrenCount)")
print("PLAYERS_SNAPSHOT: \(snapshot)")
self.player = []
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
if let playerDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let players = Players(playerKey: key, dictionary: playerDict)
self.player.append(players)
}
}
}
// self.tableView.reloadData()
}) { (error) in
print(error.localizedDescription)
print("CHET: local error")
}
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return players.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return players[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
// self.pickerView.isHidden = true
// Missing command
playerButtons.setTitle
}
//IBActions Collection for Player Names
@IBAction func playerSelectionAction(_ sender: UIButton) {
sender.setTitle("buttonName", for: .normal)
let sender = sender.tag
print(sender)
}
}
答案 0 :(得分:0)
按以下
排序 File: /usr/bin/blackbox_edit
Size: 958 Blocks: 4 IO Block: 65536 regular file
Device: 671faeah/108133098d Inode: 2251799814041428 Links: 1
Access: (0755/-rwxr-xr-x) Uid: (197609/ adrie) Gid: (197609/ adrie)
Access: 2017-06-07 15:34:50.353508600 +0200
Modify: 2017-06-07 15:54:58.823472200 +0200
Change: 2017-06-07 15:59:00.592320500 +0200
Birth: 2017-06-07 15:34:50.353508600 +0200