Accessing parent view controller (custom) properties

后端 未结 3 1067
死守一世寂寞
死守一世寂寞 2020-12-24 08:40

I have written a UITabBarController subclass (called MainViewController) and added a few instance variables, specifically a venue of type Venue. Ea

3条回答
  •  渐次进展
    2020-12-24 09:35

    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.

提交回复
热议问题