简体   繁体   English

UITableView第二和第三个标签在单元格中不显示值

[英]UITableView second & third label doesn't show values in the cell

In my Tableview, the second and third label (with tags), doesn't show anything, it's blank. 在我的Tableview中,第二个和第三个标签(带有标签)没有显示任何内容,为空白。 The second label should show "Test2" and the third label "Test3". 第二个标签应显示“ Test2”,第三个标签应显示“ Test3”。

The label tags are already configured (1, 2 & 3). 标签标签已配置(1、2和3)。 I've tried everything and still can't get this working .. :( 我已经尝试了一切,但仍然无法正常工作.. :(

Here's my code : 这是我的代码:

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!
    }
}

My tablecell : 我的表格单元格:

我的TableCell

Result : 结果: 结果

What am I doing wrong here?? 我在这里做错了什么?

Thank you in advance! 先感谢您!

The problem is in the cell size. 问题出在单元格大小上。 The labels are there but they are not in the visible area of the cell. 标签在那里,但是它们不在单元格的可见区域中。 Make your cell to be bigger or add right constraints in the storyboard. 使您的单元更大,或在情节提要中添加正确的约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM