I have this chunk of code in my ViewController named PlayViewController
:
words = [String]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "PlayTableViewCell"
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? PlayTableViewCell else {
fatalError("The dequeued cell is not an instance of PlayTableViewCell.")
}
// Configure the cell...
cell.wordLabel.text = words[indexPath.row]
if (indexPath.row == 0) {
cell.wordLabel.isHidden = false
}
return cell
}
And this is my code for TableViewCell named PlayTableViewCell
:
import UIKit
class PlayTableViewCell: UITableViewCell {
//MARK: Properties
@IBOutlet weak var wordLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
wordLabel.lineBreakMode = .byWordWrapping;
wordLabel.numberOfLines = 0;
wordLabel.isHidden = true
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
As expected, only my first wordLabel
appears in my tableView.
My goal is to reveal the second wordLabel
when the user swipes right or left anywhere on the screen and continue this way until the user reveal the last wordLabel
.
I've found how to set the swipe part (only the swipe right, behaves weirdly when the left is added) but I can't figure out how to toggle .isHidden
property when I detect the gesture.
I'm not sure to be on the right path with the cell configuration but because of the placing of the wordLabel
inside PlayTableViewCell
, it's hard to reach it outside the function tableView
.
I can index neither cell
nor wordLabel
and I can't figure out how could I reach the right wordLabel
to toggle its visibility.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…