0

I have a custom table view controller called pfTableViewController and a custom cell called customTableViewCell.

From inside my customTableViewCell I try to access an NSMutableArray of the pfTableViewController:

- (IBAction)changeEditing:(UITextField *)sender {
    pfTableViewController *pfWin = (pfTableViewController *) self.superview.superview;
    [pfWin.pfFields replaceObjectAtIndex: myId withObject: @"some text"];
}

I used superview twice because the first one calls the UITableView and the second is supposed to call the pfTableViewController but it doesn't happen, I get this error:

2013-04-17 09:48:38.017 webgopher[21757:907] -[UIViewControllerWrapperView pfFields]: unrecognized selector sent to instance 0x1d590d90

Any idea what's happening here?

If I use one more superview, it accesses the UINavigationTransitionView, that's too far I think!

JWWalker
  • 22,385
  • 6
  • 55
  • 76
Demulis
  • 73
  • 1
  • 4

2 Answers2

0

Using something like superview.superview on apple implemented views like UITableViewCell is a very bad idea. You are relying on the view hierarchy not changing. This kind of thing can break very easily between versions of iOS.

You are also assuming the table view's super view is an instance of your view controller. But the view controller instance is not a view and not part of the view hierarchy. Instead you are getting a private apple view which wraps the view controller's view.

You should implement some kind of delegate method on your cell which is implemented by the view controller. This way the view controller can be directly notified of your "changeEditing" event without you having to crawl up private view hierarchies.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
0

You can't access to a controller directly from its view. You need to look for the first controller through the responder chain. This post may be useful.-

How to get UIViewController of a UIView's superView in iPhone SDK?

Community
  • 1
  • 1
ssantos
  • 16,001
  • 7
  • 50
  • 70