Я пытаюсь передать объект в Swift от одной сцены к другой, и я получаю сообщение об ошибке с кодом ниже, говоря:Передача объекта от одной сцены к следующему
Может не вызывать indexPathForSelectedRow с нет аргументов.
Это новое требование?
Мне кажется, код ниже должен работать, но я смущен, почему это не так.
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var myTableView: UITableView!
var propertyArray: [Property] = [Property]()
override func viewDidLoad() {
super.viewDidLoad()
self.setUpProperties()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setUpProperties() {
var property1 = Property(cardImage: "image1.png", name: "Name1", location: "Hollywood")
var property2 = Property(cardImage: "image2.png", name: "Name2", location: "Astoria")
var property3 = Property(cardImage: "image3.png", name: "Name3", location: "Ft. Greene")
propertyArray.append(property1)
propertyArray.append(property2)
propertyArray.append(property3)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return propertyArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: CustomCell = tableView.dequeueReusableCellWithIdentifier("FeedCell") as! CustomCell
let property = propertyArray[indexPath.row]
println(property.name + " " + property.location)
cell.setProperty(property.cardImage, name: property.name, location: property.location)
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail" {
var detailPage = segue.destinationViewController as! DetailViewController
if let indexPath = self.tableView.indexPathForSelectedRow() {
let selectedProperty = propertyArray[indexPath.row]
detailPage.currentProperty = selectedProperty
}
}
}
}
Это странная ошибка, так как там ничего не происходит. Как определяется 'tableView'? –
Спасибо, что посмотрели, @ClaudioRedi ... Я добавил определение tableview в исходное сообщение выше. – hudsonian
Нет, он имеет в виду, что такое 'self.tableView'. Этот код работает в UITableViewController? – matt