如何使用Swift 4以编程方式从带有UIStepper的UITableViewCell获取index.row和index部分

时间:2018-06-30 11:04:41

标签: ios swift uitableview uistepper

我在尝试获取UIStepper以便将其indexPath.row和indexPath.section用于二维数组时遇到了很大麻烦。我已经找了几个小时,还没有在线找到解决方案,所以我想问一下。请查看以下代码:

@objc private func stepperValueChanged(_ sender: UIStepper!){
    print("Stepper \(sender.tag) clicked. Its value \(sender.value)")
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell: ContactCell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! ContactCell

    cell.myUIStepper.tag = indexPath.row
    cell.myUIStepper.addTarget(self, action: #selector(stepperValueChanged), for: .valueChanged)
    cell.cellDelegate = self

    let contact = twoDimensionalNamesArray[indexPath.section].names[indexPath.row]
    let contactInt = intsArray[indexPath.section][indexPath.row]
    cell.textLabel?.text = ("\(contact.name): \(contactInt)")
    print(contact.name)
    cell.accessoryView?.tintColor = contact.isFavorited ? .blue : .gray
    if showIndexPath == true {
        cell.textLabel?.text = "\(contact.name) -- \(indexPath.section), \(indexPath.row)"
    }
    return cell
}

任何帮助将不胜感激。

0 个答案:

没有答案