У меня довольно сложная ячейка в пользовательском UITableView. В этой ячейке есть несколько элементов, и я хотел бы иметь возможность отображать контроллер карты, когда пользователь нажимает на определенное изображение.Передача данных через segue через кнопку в ячейке ... Не работает ...
я первый попытался сделать это с простой кнопкой и те функции:
import UIKit
class SousCategorieViewController: UITableViewController {
var rubSegue = NSDictionary()
@IBOutlet weak var bigLogoOutlet: UIImageView!
@IBOutlet weak var titreOutlet: UILabel!
@IBOutlet weak var introOutlet: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let bigLogo = rubSegue["gfx"]!["bigLogo"]!
bigLogoOutlet.image = UIImage(named: "\(bigLogo!)")
let titre = rubSegue["gfx"]!["titre"]!
titreOutlet.text? = "\(titre!)".uppercaseString
self.title = titre as? String
tableView.estimatedRowHeight = 3000
self.tableView.rowHeight = UITableViewAutomaticDimension
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table View
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return rubSegue["corpus"]!.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let corpusArray = rubSegue.objectForKey("corpus") as! NSArray
let cell = tableView.dequeueReusableCellWithIdentifier("cellChapter", forIndexPath: indexPath) as! UniversalXIB
cell.sousTitreOutlet.text = corpusArray[indexPath.row]["soustitre"] as? String
cell.introOutlet.text = corpusArray[indexPath.row]["intro"] as? String
cell.titreOutlet.text = corpusArray[indexPath.row]["titre"] as? String
cell.imageOutlet.image = UIImage(named: (corpusArray[indexPath.row]["imageNP"] as! String))
let texteArray = corpusArray[indexPath.row].objectForKey("texteArray") as? NSDictionary
let iconesArray = corpusArray[indexPath.row].objectForKey("iconesArray") as? NSDictionary
deleteStackOrNot((corpusArray[indexPath.row]["iconesNPBool"] as! Bool), stack: cell.iconesStackOutlet)
deleteImagesOrNot((corpusArray[indexPath.row]["mapBool"] as! Bool), nameImage: (corpusArray[indexPath.row]["map"] as! String), stackRoot: cell.titreOutletStack, outlet: cell.mapOutlet)
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "mapSegue" {
if let destination = segue.destinationViewController as? Map {
if let rubIndex = tableView.indexPathForSelectedRow?.row {
print(rubIndex)
destination.nomVariable = rubIndex
}
}
}
}
}
Там в 3 клетки, и единственное, что напечатано есть:
0
0
Независимо от того, что выбранная ячейка , Что я делаю не так ?
Предоставьте еще код вашего контроллера в своем вопросе –
Et voilà, вот и все! – petaire
Итак, ваша проблема в том, что вы всегда получаете 0 как rubIndex? –