I have written a UITabBarController
subclass (called MainViewController
) and added a few instance variables, specifically a venue of type Venue. Ea
You're doing something completely wrong. parentViewController
is declared as a UIViewController
. NSLog
ing it outputs its real type due to the wonders of polymorphism.
UIViewController
doesn't have a Venue
member. Your MainViewController
does. Casting it is, in fact, the right answer. Make sure to import MainViewController.h
as well.
#import "MainViewController.h"
[...]
NSString *name = ((MainViewController *)self.parentViewController)).venue.name;
Also make sure, of course, that venue
is declared as a @property
of MainViewController, and name
is a @property
of Venue
.
Your NSLog()
statement is "seeing" it as a MainViewController
because that's what the object actually is. The problem you're having though, is that the compiler doesn't actually realize this because the parentViewController
property is declared as a plain old UIViewController
. Even though you're actually returning a subclass of it, as far as the compiler knows you're trying to call that method on a UIViewController
, and it's going to complain. Casting it to a MainViewController
will solve the issue.
int currentVCIndex = [self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];
//previous view controller
AccountViewController *account = (AccountViewController *)[self.navigationController.viewControllers objectAtIndex:currentVCIndex - 1];
account.property = object;
[account doSmthng];