views:

32

answers:

1

I am looking for a way to automatically localize texts on buttons/textfields etc and for this method I need to find all (for example) UIButton's on a UIView.

I tried the following 2 methods, but they both do no work like I want them to work:

for (UIView* subView in self.view.subviews)
{
    NSLog(@"object class : %@", [subView class]);

    if ([subView isMemberOfClass:[UIButton class]])
        NSLog(@"Button found!");
}

The problem with this piece of code is that a RoundedRectButton does not match the UIButton class, while it really is just a UIButton.

I also tried the following:

for (UIButton* button in self.view.subviews)
{
// Do my stuff
}

But the stupid thing is, is that cocoa-touch actually just lists all subviews in that for-loop (also the UITextFields etc).

Is there a way to actually just get all UIButtons from a view? Or do I really need to find controls by looking at their selectors.

+2  A: 

the first method is correct, except you need to change isMemberOfClass function to isKindOfClass:

isKindOfClass: Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class.

Vladimir
Thank you, that is indeed the method I was looking for. Thanks for the fast answer!
Wim Haanstra