Search code examples
objective-cwarningsecslidingviewcontroller

ECSliding, calling topViewController warning


I'm using ECSliding and I have this problem!

In my project there are this files:

FirstViewController(UIViewController) (topViewController)
LefViewController(UIViewController) (underLeftController)

I do this in my LeftViewController because I need to call a timer that is in FirstViewController:

FirstViewController *first = self.slidingViewController.topViewController;

and I get this warning:

Incompatible pointer types initializing 'FirstViewController *_strong' with an expression of type 'UIViewController *'

everything works fine but if it possibile I would like to get rid of it. Any idea?


Solution

  • You're looking for a cast:

    FirstViewController *first = (FirstViewController *)self.slidingViewController.topViewController;
    

    This tells the compiler "trust me, it's a FirstViewController instance". If it isn't when you come to run the code you'll get an exception.