【发布时间】:2017-03-19 03:58:33
【问题描述】:
我有 2 个文件。
- myTableViewController.swift
- myTableCell.swift
我可以在 myTabelCell.swift 函数中获取 indexPath.row 吗?
这里是 myTableCell.swift
import UIKit
import Parse
import ActiveLabel
class myTableCell : UITableViewCell {
//Button
@IBOutlet weak var commentBtn: UIButton!
@IBOutlet weak var likeBtn: UIButton!
@IBOutlet weak var moreBtn: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
}
@IBAction func likeBtnTapped(_ sender: AnyObject) {
//declare title of button
let title = sender.title(for: UIControlState())
//I want get indexPath.row in here!
}
这里是 myTableViewController.swift
class myTableViewController: UITableViewController {
//Default func
override func viewDidLoad() {
super.viewDidLoad()
//automatic row height
tableView.estimatedRowHeight = 450
tableView.rowHeight = UITableViewAutomaticDimension
}
// cell config
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//define cell
let cell = tableView.dequeueReusableCell(withIdentifier: "myTableCell", for: indexPath) as! myTableCell
}
如您所见...我试图在 myTableCell 中获取 indexPath.row,liktBtnTapped 函数。
能否告诉我如何访问或获取 IndexPath.row?
【问题讨论】:
标签: swift uitableview nsindexpath