当我点击表格 View 上的单元格时,它会发送错误的索引,但当我向左滑动时,它会发送正确的索引。它似乎在奇数索引水龙头上失败。抱歉,变量名称的意思是“已组装”。
这是代码。
override func tableView(tableView: UITableView, cellForRowAtIndexPath AssIndexPath: NSIndexPath) -> UITableViewCell {
let assCell = tableView.dequeueReusableCellWithIdentifier(assCellIdentifier, forIndexPath: AssIndexPath) as! AssTableViewCell
AssItemIndexPath = AssIndexPath.row
let Ass = assDataArray[AssIndexPath.row]
assCell.MainLabel.text = Ass.name
assCell.selectionStyle = .None
// assCell.SubLabel2.text = ("Qty In Stock \(Ass.qtyInStock)")
assCell.SubLabel.text = ("Sell Price $\(Ass.sellPrice)")
return assCell
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath AssIndexPath: NSIndexPath)
{
AssItemIndexPath = AssIndexPath.row
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath AssIndexPath: NSIndexPath) -> [AnyObject]?
{
var shareAction = UITableViewRowAction(style: .Normal, title: "Report" , handler: { (action:UITableViewRowAction!, AssIndexPath:NSIndexPath!) -> Void in
AssItemIndexPath = AssIndexPath.row
self.performSegueWithIdentifier("report", sender: nil)
})
shareAction.backgroundColor = UIColor.blueColor()
return [shareAction]
}
最佳答案
通常当我需要所选行的索引时,我会覆盖这个方法 didSelectRowAtIndexPath,我希望它有帮助。
请参阅以下链接,其中解释了有关管理选择的信息: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:didSelectRowAtIndexPath:
关于Swift TableView Tab 发送错误的索引,而编辑发送正确的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31443226/