Reputation: 4747
I subclass UIView and have an NSString member named imgName; All views added to the superview are MyCustomView;
I do this:
NSArray *arr = [view subviews];
for (int x = 0; x < [arr count]; x++)
{
MyCustomView *view = [arr objectAtIndex:x];
NSString *imgName = view.imgName; <-- Unrecognized selector
}
I really want access to that member. If I kept a different running list of subviews image names it would be problematic because I would also have to maintain their positioning in the view hierarchy (as I want the view hierarchy as is with zIndexes).
How can I get the string from [view subviews]?
Upvotes: 0
Views: 401
Reputation: 17732
You should double check that the subview is of the correct type. You can perform that check with something like this:
for ( int x = 0; x < [arr count]; ++x )
{
UIView *subView = [arr objectAtIndex:x];
if ( [subView class] == [MyCustomView class] )
{
//Perform actions on the view as needed
}
}
Odds are there is a subview that is not of your MyCustomView
type and when it is trying to cast and access that member, it cannot because it is not the appropriate type.
EDIT:
You did mention that all of your subviews added are MyCustomView
. I personally wouldn't trust the iOS structure to not have subview already embedded in a UIView
Upvotes: 2