私は2つのファイルを持っています。cell.swiftでindexPath.rowを取得する方法
- myTableViewController.swift
- myTableCell.swift
私はmyTabelCell.swift機能でindexPath.rowを得ることができますか?
はここmyTableViewController.swiftclass 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、liktBtnTapped機能でindexPath.rowを取得しようとしている。ここ
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!
}
myTableCell.swift
です。私はIndexPath.rowにアクセスしたり取得したりできますか教えてください。
素晴らしい拡張子と思われます。あなたはどのように使用するコードを入れてもらえますか? –
'UITableViewCell + IndexPath.swift'という名前の新しいファイルを作成し、上記のコードを追加するだけです。次に、セルの内部で、 'self.indexPath'を使ってインデックスパスを取得できます。 – Callam
ありがとう〜!それはうまく動作します –