Hi,
I have 2 ViewControllers and a Segue between them that I trigger programmatically.
The first ViewController has some data stored in self.myCustomProperty that it needs to pass to the 2nd controller. The second ViewController with class name "MyTableViewController" which inherits from UITableViewController has a property customData which implies also the corresponding setter method "setCustomData:somedata".
The first ViewController performs the Segue on a certain event:
[self performSegueWithIdentifier:@"MyCustomSegue" sender:self];which starts this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if( [segue.identifier isEqualToString:@"MyCustomSegue"] ){
MyTableViewController *destinationController = segue.destinationViewController;
[destinationController setCustomData:self.myCustomProperty];
}
} The problem is that [destinationController setCustomData:self.myCustomProperty] causes
'NSInvalidArgumentException', reason: '-[UITableViewController setCustomData:]: unrecognized selector sent to instance 0x...
After inspecting the problem I noticed that destinationController variable has the class "UIViewController" class instead of "MyTableViewController". I suppose, the exception is thrown, because UIViewController does not have the customData property.
I have searched for some time in Internet but neither did I find mentions of such problems nor did I find a way to turn UIViewController into MyTableViewController. The only method to do the latter that I have found is "object_setClass(id obj, Class cls)", but using it can cause serious problems.
How can I solve the issue?