![](/img/trans.png)
[英]Retrieving a column from SQLite to a label in cell of table view Swift iOS
[英]Retrieving the values of array in table view cell swift ios
我正在尝试在表视图单元格中检索wInstockArray
的值。 目前, wInstockArray
为空,我在单击按钮时插入一个字符串并追加到数组中。 但是当我重试cellForRowAtIndexath
方法中的值时,它给出了错误
索引超出范围
我定义的是:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return wInstockArray.count + 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let firstCell = firstTableView.dequeueReusableCell(withIdentifier: "firstCell")! as UITableViewCell
if wInstockArray.count == 0 {
print("no widgets in instock")
} else {
firstCell.textLabel?.text = wInstockArray[indexPath.row]
print("\(wInstockArray.count)") //prints 1
return firstCell
}
}
内部按钮单击动作
wInstockArray.append(item)
内部按钮点击方法,请重新加载表格。
YOUR_TABLE.reloadData()
并更新此方法,
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return wInstockArray.count
}
在numberOfRowsInSection
方法中,返回wInstockArray数组计数
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return wInstockArray.count
}
在按钮单击动作内部,重新加载tableView
wInstockArray.append(item)
tableView.reloadData()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.