I’ve created a UIViewController which contains a view with a custom class that I’ve built. I’ve connected the view to the File’s Owner view outlet. It renders properly and I don’t have any real problems. However, I want to call a method within my view from my view controller instance, say it’s called drawSomething. So within a method in my controller, I use:
[self.view drawSomething];
It works. But I get a pre-compiler warning because it appears to not know the methods within my custom view definition. Is my approach wrong here? I can create a local variable and cast it to make the warning go away obviously. I’ve imported the view’s header file, so that’s not the issue.
I feel like I’m missing something trivial.
.h of my custom view contains:
-(void) drawSomething;
.m of my custom view contains:
-(void) drawSomething { <code> };
self.viewis basically a pointer to aUIViewused as the main view for the view controller. Since your view is a custom class with custom methods, you need a cast to your custom class to call your custom methods:Otherwise, you are calling
drawSomethingon a standardUIView, which does not exist.