在我的 Tableview 中,第二个和第三个标签(带有标签)没有显示任何内容,它是空白的。第二个标签应显示“Test2”,第三个标签应显示“Test3”。
标签标记已配置(1、2 和 3)。我已经尝试了所有方法,但仍然无法正常工作..:(
这是我的代码:
import UIKit
import FirebaseDatabase
import FirebaseAuth
struct exerciseStruct {
let exerciseName : String!
let mainMuscle : String!
let rate : String!
}
class ExercisesViewController: UITableViewController {
var exercises = [exerciseStruct]()
override func viewDidLoad() {
super.viewDidLoad()
self.exercises.insert(exerciseStruct(exerciseName: "Test1", mainMuscle: "Test2", rate: "Test3"), atIndex: 0)
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return exercises.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell")
let label1 = cell!.viewWithTag(1) as! UILabel
label1.text = exercises[indexPath.row].exerciseName
let label2 = cell!.viewWithTag(2) as! UILabel
label2.text = exercises[indexPath.row].mainMuscle
let label3 = cell!.viewWithTag(3) as! UILabel
label3.text = exercises[indexPath.row].rate
return cell!
}
}
我的表格单元格:
我在这里做错了什么?
提前谢谢您!
最佳答案
问题出在单元格大小上。标签在那里,但它们不在单元格的可见区域中。使您的单元格更大或在 Storyboard中添加正确的约束。
关于ios - UITableView 第二个和第三个标签不显示单元格中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39169922/