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

  • Home
  • SEARCH
  • 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 6576267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:29:28+00:00 2026-05-25T15:29:28+00:00

I have an array of view controllers (there are more that I have shown):

  • 0

I have an array of view controllers (there are more that I have shown):

..
settings = [[settingsSettingTab alloc] initWithNibName:@"settingsTab" bundle:nil];
other = [[otherSettingTab alloc] initWithNibName:@"otherTab" bundle:nil];
..

NSArray *views = [NSArray arrayWithObjects:settings,other, nil];

I then loop through them and assign some details to them before pushing them:

for (int i = 0; i < views.count; i++) {
...
NSString *className = NSStringFromClass([[views objectAtIndex:i] class]);
Class myClass = NSClassFromString(className);

myClass *subView = (myClass*)[views objectAtIndex:i];

[self.scrollView addSubview:subView.view];
}

How can I assign the right class to the *subView. It worked fine when I had only one type of view in my array and then I just used:

settingTab *subView = (settingTab*)[views objectAtIndex:i];

But now I need to check and use the right one. I have googled the question, but I’m not sure of how I would describe it? (dynamic typing? Duck typing?) Any pointers would be really appreciated.

Thanks

EDIT:

Here is the whole code:

NSArray *titles = [NSArray arrayWithObjects: @"Basics", @"Colours", @"Shapes", @"Settings", @"Other", nil];

basics = [[basicsSettingTab alloc] initWithNibName:@"basicsTab" bundle:nil];
colours = [[colorsSettingTab alloc] initWithNibName:@"colorsTab" bundle:nil];
shapes = [[shapesSettingTab alloc] initWithNibName:@"shapesTab" bundle:nil];
settings = [[settingsSettingTab alloc] initWithNibName:@"settingsTab" bundle:nil];
other = [[otherSettingTab alloc] initWithNibName:@"otherTab" bundle:nil];

NSArray *views = [NSArray arrayWithObjects: basics,colours,shapes,settings,other, nil];

for (int i = 0; i < views.count; i++) {


    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * i + 20;
    frame.origin.y = 0;

    CGFloat newWidth = 280;
    CGFloat newHeight = 320;
    CGFloat locx = 0;
    CGFloat locy = 0;

    CGRect panel = CGRectMake(locx, locy, newWidth, newHeight);

    frame.size = panel.size;//self.scrollView.frame.size;
    //subview.view.backgroundColor = [colors objectAtIndex:i];

    NSString *className = NSStringFromClass([[views objectAtIndex:i] class]);
    Class myClass = NSClassFromString(className);

    myClass *subView = (myClass*)[views objectAtIndex:i];
    [subView.view setFrame:frame];
    subView.tabTitle.text = [titles objectAtIndex:i];

    [subView.view.layer setCornerRadius:5.0f];
    [subView.view.layer setMasksToBounds:YES];

     subView.delegate = self;

    [self.scrollView addSubview:subView.view];
}

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * views.count, self.scrollView.frame.size.height);
pageControl.numberOfPages = views.count;

}

  • 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-25T15:29:29+00:00Added an answer on May 25, 2026 at 3:29 pm

    From your edit, we see that you have a property tabTitle on each of your custom view controllers. I would recommend that you create a new UIViewController subclass that implements tabTitle, and use that as the superclass for each of your custom controllers. That way your code only needs to know that they are all a MyTabViewController class (for want of a better class name!). So in your for loop:

    MyTabViewController *subview = (MyTabViewController *)[views objectAtIndex:i];
    [subview.view setFrame:frame];
    [subview.tabTitle setText:[titles objectAtIndex:i]];
    
    // ...
    
    [self.scrollView addSubview:subView.view];
    

    Everything else (view property for example) is defined by UIViewController, from which all your subclasses are descendants.

    EDIT

    Incidentally, I would be careful about the naming of your objects – your view controllers are not views. In particular, this might cause confusion where you have subview.view. Perhaps more appropriate would be subviewController.view, or even just controller.view?

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

Sidebar

Related Questions

I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have an array of numbers that potentially have up to 8 decimal places
I have an app that has a UINavigationController that pushes a UITabBarController into view.
In one of my Controllers, I have multiple URLs that will ultimately render in
So we have a real-estate-related site that has controller/action pairs like homes/view, realtors/edit, and
I have created a web-service app and i want to populate my view controllers
I have two tables, users{name,id,age_range_id} and age_ranges{id,range_name} . There are also two models, controllers
Example: I have 10 view controllers, which are all allocated and initialized in the
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>

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.