Swift TableView Tab 发送错误的索引,而编辑发送正确的索引

标签 swift uitableview segue swipe tap

当我点击表格 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/

相关文章:

swift - 如何从 Apollo iOS Closure 中获取值(value)?/How to "wrap"a closure in a function?

ios - 根据单元格索引路径向 TableView 单元格元素添加渐变层

ios:如何以编程方式从细节到 TableView

ios - 在 Objective-C 中传回 NSManagedObject

ios - Swift - UITableView 不放置 UIimage=nil

ios - 执行 FFT 以查找和弦音频样本的基频

ios - 有时尝试从 UITableView 中删除行时会崩溃

ios - 尝试在...上呈现...其 View 不在窗口层次结构中

ios - 展开可选值(由 data.withUnsafeBytes(_ :)) sometimes does not work with guard let 返回

ios - uitableview 默认图像显示不同大小?