I have a list view in my app and I'm adding there the cells dynamically.
For each cell I want to attach a segue and thanks to it open a UIViewController (called FullUser
) when user presses the cell (that UIViewController will contain the data passed by this segue, fetched from the specific cell chosen by user, stored in a structure called SingleUser
).
So I have this method:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath) as! SingleEventCell
let user = self.items[indexPath.row] as? SingleUser
self.performSegueWithIdentifier("fullUserFromListSegue", sender: user)
}
and then:
var fullUserDetails: FullUser?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "fullUserFromListSegue"){
fullUserDetails = segue.destinationViewController as? FullUser
//now I want to set the textfield on the other panel:
let user2 = sender as? SingleUser
var username = user2?.username
fullRequestDetails!.username.text = username!
}
}
but I'm getting error and when I'm checking it in debugger I see that user2
is nil. Why so? I want to store there a SingleUser
object, so how can I pass it there?