簡體   English   中英

UITableView第二和第三個標簽在單元格中不顯示值

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

在我的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!
    }
}

我的表格單元格:

我的TableCell

結果: 結果

我在這里做錯了什么?

先感謝您!

問題出在單元格大小上。 標簽在那里,但是它們不在單元格的可見區域中。 使您的單元更大,或在情節提要中添加正確的約束。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM