如何显示我的TableView Controller的UILabel文本?

时间:2019-06-22 23:27:32

标签: ios swift uitableview uilabel

enter image description here

我在这里使用Realm数据库。我有一个带有很多UILabel的tableview控制器,我是通过从那些Xcode UI元素中拖动来创建的。在这种情况下,我尝试使用数据源方法通过设置cell = UILabel.text来显示UILabel文本。但是,Xcode给我一个错误,说UILabel没有属性“ text”,这与我从苹果纪录片中看到的有所不同。

我应该怎么做才能在TableView Controller上显示那些UILabel文本。如果我现在在Xcode上运行项目,则不会显示所有UILabel文本。

我认为我可以使用以下方式显示这些UILabel文本:


import UIKit
import RealmSwift

class NewIdeaCreation: UITableViewController {

    let realm = try! Realm()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
   return ideaTable.count ?? 1
}

// Provide a cell object for each row.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

   let cell = tableView.dequeueReusableCell(withIdentifier: "cellTypeIdentifier", for: indexPath)

   // Configure the cell’s contents.
   cell.textLabel!.text = UILabel.text[indexPath.row]

   return cell
}

1 个答案:

答案 0 :(得分:0)

您不能直接访问T = int(input()) for i in range(0,T): cost_of_green = 0 cost_of_purple =0 G = int(input()) P = int(input()) n = int(input()) for j in range(0,n): X = int(input()) Y = int(input() cost_of_green =cost_of_green + X*G cost_of_purple = cost_of_purple + Y*P print(cost_of_green+cost_of_purple) 的{​​{1}}属性,因为它不是类属性。 text是实例属性。您首先创建一个UILabel的实例,然后将其设置为text的值。像这样

UILabel

text已经有一个名为let label = UILabel() label.text = "Some text" 的{​​{1}}实例。您可以像这样设置其“ UITableViewCell”属性的值。

UILabel