0
다른 셀 및 버튼 활성화 :내가 이미지 (잘린 1) 몇 가지 텍스트 레이블이있는 사용자 정의 셀 클래스가
class CustomTVC: UITableViewCell {
/* Outlets */
@IBOutlet weak var imageHolder: UIImageView!
@IBOutlet weak var concatenatedTitleHolder: UILabel!
@IBOutlet weak var localDateHolder: UILabel!
@IBOutlet weak var descriptionHolder: UILabel!
@IBOutlet weak var seeMoreButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
}
}
을 때 버튼을 사용자가 클릭, 그것을 잘라낸 텍스트 레이블의 전체 설명을 보여줍니다. 그러나 지금 내가 가진 문제는 사용자가 특정 셀의 단추를 클릭하면 사용자가 클릭 한 셀의 전체 설명과 다른 셀의 전체 설명을 보여줍니다.
tableview가 dequeueReusableCellWithIdentifier를 통해 셀을 재사용하기 때문에 발생하는 이유를 알고 있습니다. 사용자가 특정 셀의 단추를 클릭 할 때 해당 셀의 전체 설명 만 표시되는지 확인하는 함수를 구현하는 방법은 무엇입니까? tableview에 대한
코드 :
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("customCell", forIndexPath: indexPath) as! CustomTVC
if listOfShows.count != 0 {
// Downloading and displaying picture
if let downloadPicture: UIImage = helperFunctions.downloadImage(listOfShows[indexPath.row].imageLink) {
cell.imageHolder.image = downloadPicture
}
// Enlarging/dismissing picture
cell.imageHolder.userInteractionEnabled = true
let newTapped = UITapGestureRecognizer(target: self, action: #selector(MainTVC.imagedTapped(_:)))
cell.imageHolder.addGestureRecognizer(newTapped)
// Concatenating channel + series + episode title
let concatenatedTitle = listOfShows[indexPath.row].channel + " " + listOfShows[indexPath.row].series + " " + listOfShows[indexPath.row].episodeTitle
// Converting into local date/time
let universalTime = helperFunctions.localDateAndTimeConverter(listOfShows[indexPath.row].originalAirDate)
/* Other labels */
cell.concatenatedTitleHolder.text = concatenatedTitle
cell.localDateHolder.text = universalTime
cell.descriptionHolder.text = listOfShows[indexPath.row].description
cell.seeMoreButton.tag = indexPath.row
cell.seeMoreButton.addTarget(self, action: #selector(MainTVC.buttonTapped(_:markedArray:)), forControlEvents: .TouchUpInside)
resetCellSettings(cell)
}
return cell
}
func buttonTapped(sender: UIButton, markedArray: [Bool]) {
let indexPath = NSIndexPath(forRow: sender.tag, inSection: 0)
let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomTVC
cell.seeMoreButton.hidden = true
cell.descriptionHolder.numberOfLines = 0
cell.descriptionHolder.lineBreakMode = NSLineBreakMode.ByWordWrapping
cell.descriptionHolder.sizeToFit()
}
func resetCellSettings(cell: CustomTVC) {
cell.seeMoreButton.hidden = false
cell.descriptionHolder.numberOfLines = 1
cell.descriptionHolder.lineBreakMode = NSLineBreakMode.ByTruncatingTail
cell.descriptionHolder.sizeToFit()
}