我写了这个代码:如何在Swift中填充表格视图?
//Basic methods
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.DevicesTableView.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell")
self.DevicesTableView.dataSource = self
}
var array = ["one","two"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return array.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: UITableViewCell! = self.DevicesTableView
.dequeueReusableCellWithIdentifier("cell") as UITableViewCell!
cell.textLabel!.text = self.array[indexPath.row]
return cell
}
因此,代码工作得很好,并表明我充满了实现代码如下:
ROW1“一” 行2“二”
但我怎么能填写TableView不是在我的程序开始,但随时随地?我尝试在其他函数viewDidLoad中调用下面的方法,但它不起作用...为什么?
self.DevicesTableView.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell") self.DevicesTableView.dataSource = self
编辑:
我想显示未在我的节目的开始时被初始化的阵列。它包含用户搜索后的一些BLE设备。