1

I know this is an issue with importing a class but I'm not sure which one I need.

Currently I have public class postWithTitleAndImageTableViewCell: UITableViewCell, UINavigationControllerDelegate { and my issues that arise can be seen here: xcode What classes do I need to import to fix my issue?

uhfocuz
  • 3,178
  • 2
  • 13
  • 27
  • This is unusual app design - normally the push occurs within the `UITableViewController` that holds the `UITableViewCell`. And I would expect the information to be passed to the next view controller (your `DetailedViewController`) to be set in `prepareForSegue:sender:`. Even if you are not using segues I would still expect the push to come from the `UITableViewController`. – Robotic Cat Jan 25 '15 at 19:15
  • This question (http://stackoverflow.com/q/24222640/558933) has answers in Swift that uses both `prepareForSegue:sender:` and `tableView:didSelectRowAtIndexPath:` to push a new controller onto the stack and set variables in the new view controller. This is basically what you are trying to do. – Robotic Cat Jan 25 '15 at 19:19
  • @Robotic Cat I know this is unusual but necessary because I need to verify where the taps location was and decide wether to handle it or not. – uhfocuz Jan 25 '15 at 20:17

1 Answers1

1

UITableViewCell has neither a storyboard nor navigationController property. UIViewController has both of these. They are not interchangeable, they are different types. If you want to access the properties of the cell's tableViewController, you will need to store a reference to the view controller in your cell or find another way to get to it.


Referencing the view controller from the table view

In your table view controller:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithReuseIdentifier("CellIdentifier", indexPath: indexPath)
    cell.viewController = self
    return cell
}

In your table view cell add a property to hold the view controller:

var viewController: UIViewController?

override func prepareForReuse() {
    super.prepareForReuse()
    viewController = nil
}
bjtitus
  • 4,231
  • 1
  • 27
  • 35
  • How might I store a reference to the view controller so that it can be called with values as my code demonstrates – uhfocuz Jan 25 '15 at 20:19