Я пытаюсь взять данные из своего табличного представления на контроллер вида. Пока я могу перемещать данные, которые отображаются в ячейке, но по какой-то причине я не могу взять переменную.Передать переменную в tableview во время segue IndexPath
Вот что уже работает
//Prepare for Segue
destination.titleSegue = (cell?.textLabel?.text!)!
destination.priceSegue = (cell?.detailTextLabel?.text!)!
destination.imageSegue = (cell?.imageView?.image!)!
Все, что получает данные передаются на второй взгляд.
Теперь я покажу вам мой cellForRowAtIndexPath
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Subtitle , reuseIdentifier: cellId)
cell.backgroundColor = UIColor.clearColor() //Makes colour of cells clear so we can see the background
cell.textLabel?.text = userList[indexPath.row].title //Shoes Name
cell.textLabel?.textColor = UIColor.whiteColor() //Sets text colour to white
cell.detailTextLabel?.text = "$\(userList[indexPath.row].price!)" //Displays price of shoes
cell.detailTextLabel?.textColor = UIColor.whiteColor() //Sets text colour to white
//LOOK HERE STACK OVERFLOW*******
let descriptionText = userList[indexPath.row].description
let URLString = self.userList[indexPath.row].listingImageURL //Finds URL of profile image
let URL = NSURL(string:URLString!)! //Converts URL Stirng to NSURL
cell.imageView?.frame = CGRectMake(10,10,100,100) //Sets frame size for images on tableview TODO
cell.imageView?.contentMode = .ScaleAspectFit //Sets image to aspect fill for image TODO
cell.imageView?.hnk_setImageFromURL(URL) //Displays image on table view from Haneke Framework
return cell
}
Если вернуться к моему prepare for segue
, что мне нужно позвонить, чтобы разобрать «descriptionText» переменную из CellForRowAtIndexPath
, чтобы получить данные, чтобы перейти к второй контроллер просмотра?
Где вы звоните ваш 'performSegue' код? –
Как всегда ** ** не получайте данные из представления (ячейки), получите его из модели ('userList'). В зависимости от способа выполнения segue (непосредственно или через 'didSelect ...') вам нужно получить индексный путь в 'prepareForSegue', либо через ячейку в параметре' sender', либо через 'tableView.indexPathForSelectedRow' – vadian