作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了这段代码:
//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
}
所以代码运行得很好,并向我显示了填充的表格 View :
第 1 行“一”第 2 行“二”
但是我怎样才能不在程序开始时而是在其他任何时候填充TableView呢?我尝试在 viewDidLoad 的其他函数中调用下面的方法,但它不起作用......为什么?
self.DevicesTableView.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell")
self.DevicesTableView.dataSource = self
编辑:
我想显示一个在程序开始时未初始化的数组。用户搜索到后,其中包含一些BLE设备。
最佳答案
很简单
例如:
var array = ["one","two","Three","Four"] // your array will take no.of.row in section
DevicesTableView.reloadData()
关于ios - 如何在 Swift 中填充 TableView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32799098/
我是一名优秀的程序员,十分优秀!