어떤 tableviewcell을 선택했는지 알기 위해 그 셀의 레이블 값을 가져 와서 다음보기 컨트롤러로 전달하려고합니다. 내 셀의 레이블 값은 string
이고 숫자 값은 Int
입니다. firebase 데이터베이스를 사용하여 모든 데이터를 가져옵니다.어떤 tableviewcell이 선택되었는지 확인하고 다른 viewcontroller에 값을 전달하십시오.
내 코드 :
import UIKit
class PlacesTableViewController: UITableViewController {
//MARK: Properties
@IBOutlet weak var placesTableView: UITableView!
var places = [Places]()
override func viewDidLoad()
{
super.viewDidLoad()
// Loads data to cell.
loadData()
}
override func numberOfSections(in tableView: UITableView) -> Int
{
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
//return the number of rows
return places.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "PlacesTableViewCell"
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? PlacesTableViewCell else {
fatalError("The dequeued cell is not an instance of PlacesTableView Cell.")
}
let place = places[indexPath.row]
cell.placeLabel.text = place.name
cell.ratingControl.rating = place.rating
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
print(places[indexPath.section])
self.performSegue(withIdentifier: "ShowCommentsTableViewController", sender: nil)
}
}
내가 스레드에 대해 감사해야 할 것을 이해합니다. 하지만 prepareForSegue func를 재정의하려고 할 때 문제가 있습니다. –
stackoverflow에서 질문을 게시하고 주시기 바랍니다. :) –
나는 그것을 발견했다. Swift 3 업데이트 코드였습니다. 'override func prepare (segue : UIStoryboardSegue, 발신자 : Any?)'대신에. –