Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:30:33+00:00 2026-05-26T15:30:33+00:00

I subclass UIView and have an NSString member named imgName; All views added to

  • 0

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]?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:30:33+00:00Added an answer on May 26, 2026 at 3:30 pm

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIView subclass with an added observer for the UIKeyboardWillShowNotification and UIKeyboardWillHideNotification
I have a UIView subclass ( CustomView for purposes of this question) that has
I have a UIView subclass. This subclass has multiple subviews. Is it possible to
I have subclass UIView class in a Bounce class with Accelerometer. This Bounce class
I have a UIView subclass that draws a simple rectangle with this code: -
I have this in a custom UIView subclass init function: self.clearsContextBeforeDrawing=YES However, each time
I have a UIView subclass to which I have added a UIPanGestureRocognizer: _panGestureRecognizer =
I have a UIView subclass, and within this I call this other UIView subclass.
I have a UIView subclass and I want the keyboard to appear when it
I have a UIView subclass that draws itself when -drawRect: is called. It only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.