I have a class that inherits from UIView
However when trying to use the follow (UIView *)viewWithTag:(NSInteger)tag I get the warning: *incompatible Objective-C types initializing ‘struct UIView *’, expected ‘struct CustomView ‘
Right now I have made a custom method that returns my custom view, the method uses a for loop with view.subviews since the views I am looking for come from the same superview. I do a conditional check if the tag matches the one I am searching for then I return the view.
I suppose I am just wondering if there is a better practice to this?
Thanks
You’re probably doing:
viewWithTag:returns aUIView, not aCustomView. There are a couple ways around this:Casting. If you are absolutely sure that you’ll only ever get a
CustomViewby doing this, then you can do:Reflection. If you’re not sure that you’re going to get a custom view, then assign it into a
UViewreference and decide later what to do with it: