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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:20:42+00:00 2026-05-12T18:20:42+00:00

I have a best practice type of question regarding Nibs and UISegmentedControls. I have

  • 0

I have a best practice type of question regarding Nibs and UISegmentedControls.

I have a nib file which contains a UISegmentedControl with 3 buttons. Each of which displays a different view in the main part of the window when toggled.

Everything is working fine but I suspect my approach is flawed and was wondering if someone could suggest the way I was “meant” to do it.

Currently in the NIB I have 3 UIViews which are overlayed on top of one another and then in the .m file I modify each UIViews .hidden to hide and reveal the one I am interested in.

- (IBAction)segmentAction:(id)sender
{
    if([sender selectedSegmentIndex] == 0)
    {
        [self.view1 setHidden:NO];
        [self.view2 setHidden:YES];
        [self.view3 setHidden:YES];
    }
    else if([sender selectedSegmentIndex] == 1)
    {
        [self.view1 setHidden:YES];
        [self.view2 setHidden:NO];
        [self.view3 setHidden:YES];
    }
    else if([sender selectedSegmentIndex] == 2)
    {
        [self.view1 setHidden:YES];
        [self.view2 setHidden:YES];
        [self.view3 setHidden:NO];
    }
}

Everything “works” but the nib file is a pain to edit as you can’t easily “turn off” the other UIViews so I invariably select the wrong element on the canvas. Also IB complains that: “This view overlaps one of its siblings” in the info dialog.

What is the approach I should be taking given that I would like all of the views to be laid out in InterfaceBuilder. Should I have 4 nib files? If so how should I load them in when a segmentControl is pressed? Any sample code you can direct me to?

thanks

  • 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-12T18:20:42+00:00Added an answer on May 12, 2026 at 6:20 pm

    off the top of my head, here are a couple things you can try:

    1) make 3 separate UIView objects in IB, but don’t add them to the view heirarchy

    Assuming that you have a view controller where all three views are contained, you can, in IB, create the 3 views by dragging each view from the library to the window titled YourNib.nib or YourXib.xib. So don’t drag the views into the view controller’s main view.

    Now you can double click each one and edit them on their own, without having to try to select the different views because they’re overlapped (because they aren’t)

    in the connections tab, connect the view controller’s view property to one of the views.

    this sets the default.

    now in your code, you can change which view is connected to:

    [myViewController setView:view2];

    and reload the views.

    2) make one really tall view (or really wide view) and change the y-position of the view w/ respect to the parent view’s frame when you click a segmented view button so that it appears to user as if they’re going to separate pages

    this makes it easy to animate and transition between “views”. though will use more memory because you have all elements loaded even when they’re not visible. but you were doing that anyway.

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

Sidebar

Related Questions

I have a question regarding best-practice when including headers. Obviously include guards protect us
What is the general best practice for this type of functionality. I have a
I have a best practice question. I'm developing a OO MVC framework in PHP,
I have a design/best practice question relating to MVC3. I have a front page
I have a question about jQuery load best practice. Imagine the following situation: $(#div).on('click',
So I have a question of best practice in terms of extending functionality of
Simple question on best practice. Say I have: public class Product { public string
Hey, I have a question regarding code structure, and was wondering what the best
I have a base type which stores information about a question in a question
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record

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.