【发布时间】:2016-06-07 04:47:31
【问题描述】:
我正在从数据库中检索一些数据并将它们附加到一个数组中。然后,(检索完成后),我重新加载数据并将这些数据放入 TableView。在我的动态 TableView 中,我有按钮,所以在 cellForRowAtIndexPath 中,我在那里声明它。
我检查并确保检索到的数据(所以数组)不为空。但是,按钮的选择器抱怨
表达式解析为未使用的 i 值
var users = [String]()
// First I store in users array and reload tableView
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! MyTableViewCell
cell.myBtn.tag = indexPath.row
cell.myBtn.addTarget(self, action: #selector(ViewController.btnClicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
func btnClicked (sender:UIButton) {
let btnRow = sender.tag
if !self.users.isEmpty {
self.users[btnRow] // This line complains: Expression resolves to an unused i-value
}
}
【问题讨论】:
-
所以删除该行。它什么也没做,这就是警告消息告诉你的。
-
我需要访问数组中的值
-
您正在访问它但没有使用它。
-
@matt Ye,这就是原因。非常感谢
-
其实是一个未使用的左值(也就是小写L的左值,就像利马一样)。
标签: ios arrays swift uitableview uibutton