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 6171283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:11:09+00:00 2026-05-23T23:11:09+00:00

Which is the correct way of enumerating through sub views to find text fields?

  • 0

Which is the correct way of enumerating through sub views to find text fields?

NSMutableArray *mutableTFs = [[NSMutableArray alloc] init];

for (UIView *view in [self.view subviews]) {
    if ([view isKindOfClass:[UITextField class]]) {            
        [mutableTFs addObject:view];
    }
}

OR

NSMutableArray *mutableTFs = [[NSMutableArray alloc] init];

for (UITextField *textField in [self.view subviews]) {
    [mutableTFs addObject:textField];
}

I know this isn’t the correct wording, but what I don’t understand is if it is the top method, how do you ‘convert’ it from a view to a text field?

  • 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-23T23:11:10+00:00Added an answer on May 23, 2026 at 11:11 pm

    Which is the correct way of enumerating through sub views to find text
    fields?

    The first method is the correct one. The second method will iterate over all the subviews, not just the subviews with type UITextField. The type in the for() is only a hint to the compiler.

    For more information, see this question.

    how do you ‘convert’ it from a view to a text field?

    This is what typecasting is for.

    for (UIView *view in [self.view subviews]) {
        if ([view isKindOfClass:[UITextField class]]) {
            // you don't need to cast just to add to the array         
            [mutableTFs addObject:view];
            // typecasting works as it does in C
            UITextField *textField = (UITextField *)view;
            // do something with textField
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am struggling to find out the syntactically correct way in which to add
Does anyone know the correct way to explicitly specify which rules Gendarme will use?
Which is more correct way to return from function: void function() { // blah
Which is the correct way to specify a hover/focus/visited state on a link which
I was wondering which is the correct way? _tcscpy(tchar_pointer, _tcslen(tchar_pointer), _T(Hello World)); or _tcscpy(tchar_pointer,
Which is the correct way to specify a reference. I know both works with
Which is the correct way of making strlen return the lenght of several strings
HI, Which is the correct way to get the value from a JComboBox as
I have a question about the correct way to switch views for an iPhone
Which is the correct way of providing values to a abstract factory method? Eg.

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.