将tableview单元格文本标签附加到一个空数组中

问题描述

我想获取显示在表格视图单元格上的所有索引路径整数。现在,单元格上的数字是1-5。那就是应该附加到数组emptyA上的内容。我试图在索引路径上进行压缩,但这不起作用。我的所有代码均在没有使用演示图板的情况下突出显示。代码应该在加载后的视图中追加数组。

   import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    var emptyA = [Int]()
    func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath)
        cell.textLabel?.text =    "\([indexPath.row+1])"
     
        return cell
    }
    
    var theTable = UITableView()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.addSubview(theTable)
        theTable.frame = CGRect(x: 100,y: 100,width: 100,height: 300)
        theTable.delegate = self
        theTable.dataSource = self
        theTable.register(UITableViewCell.self,forCellReuseIdentifier: "cell")
        //need this part
        emptyA.append()
        
    }


}

解决方法

您可以通过from random import randrange from time import sleep from os import system while True: system("cls") rand = randrange(10) rand+=60 print("Random number: ",rand) sleep(1) 方法在indexPath.row中添加emptyA,即

tableView(_:cellForRowAt:)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...