简体   繁体   中英

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. The second label should show "Test2" and the third label "Test3".

The label tags are already configured (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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