【发布时间】:2019-09-10 11:03:55
【问题描述】:
我正在构建一个表格视图,其中只包含一个按钮,带有不同的标签。
我正在使用表格视图来显示按钮列表。
这是一个包含按钮名称的结构。
struct post {
let name : String
}
我已将数据从 firebase 推送到结构帖子。
var posts = [post]()
override func viewDidLoad() {
super.viewDidLoad()
let db = Firestore.firestore()
db.collection(Auth.auth().currentUser?.uid as Any as! String).getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
// print("\(document.documentID) => \(document.data())")
self.posts.insert(post(name: document.documentID), at: 0)
}
self.contents.reloadData()
}
}
}
这些是表格视图的正常功能
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! cellview
cell.programnames.titleLabel?.text = posts[indexPath.row].name
return cell
}
cellview.swift 设计如下
class cellview: UITableViewCell {
@IBOutlet weak var programnames: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
请告诉我我的错误。按钮“程序名”在模拟器的表格视图中不可见
【问题讨论】:
-
@AamirR 但按钮的标签没有改变,只有一行可见。
标签: ios swift firebase tableview