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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:05:08+00:00 2026-05-29T06:05:08+00:00

ViewDidLoad v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; v2= [[UIView alloc] initWithFrame:CGRectMake(0, 0,

  • 0

ViewDidLoad

v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
v2= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

// then i add componants to both these views.

for v1, i add several textfileds, and button
for v2, i add several labels, and a image

and in the same viewDidLoad method i add a segment controller to the navigationcontroller;

segment = [[UISegmentedControl alloc] initWithFrame:CGRectMake(x,y, height,width)];           
segment .segmentedControlStyle = UISegmentedControlStylePlain;
[segment insertSegmentWithTitle:@"first" atIndex:0 animated:NO];
[segment insertSegmentWithTitle:@"second" atIndex:1 animated:NO];
[segment setSelectedSegmentIndex:0];
segment .momentary = YES;
[segment addTarget:self action:@selector(segmentclicked:) forControlEvents:UIControlEventValueChanged];
segmentControllerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 50.0)];
segmentControllerView .autoresizingMask = 0;
[segmentControllerView  addSubview:segment ];
self.navigationItem.titleView = segmentControllerView ;

Now in the ;

-(void)segmentclicked:(id)sender {
if ((((UISegmentedControl *)sender).selectedSegmentIndex) == 0 ) {
    [v1 setHidden:YES];
    [v2 setHidden:NO];

    [self.view addSubview:self.v1];
    [loginSignupSegment setSelectedSegmentIndex:0]; <<<<<<<<<
    [segment addSubview:segment];
    self.navigationItem.titleView = segmentControllerView;
} else {
    //toggle the correct view to be visible
    [v2 setHidden:YES];
    [v1 setHidden:NO];     

    [self.view addSubview:self.v2];
    [segment setSelectedSegmentIndex:1]; <<<<<<<<<<<<<<<<
    [segmentControllerView addSubview:segment];
    self.navigationItem.titleView = segmentControllerView;
}}

What hapence is that when i switch views, i don’t get the segment respected to the view highlighted (I have done it in the code but its not showing off) – see the <<<<<<< in the code.

How can i solve this ?

  • 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-29T06:05:08+00:00Added an answer on May 29, 2026 at 6:05 am

    i do not think your code is the best way to do this. But i do not know all the project.
    For solve it remove

    segment.momentary = YES;
    

    and replace -(void)segmentclicked:(id)sender with:

    -(void)segmentclicked:(id)sender {
        if ((((UISegmentedControl *)sender).selectedSegmentIndex) == 0 ) {
            [v1 setHidden:YES];
            [v2 setHidden:NO];
    
            [self.view addSubview:v1];
            [segment setSelectedSegmentIndex:0];
        } else {
            //toggle the correct view to be visible
            [v2 setHidden:YES];
            [v1 setHidden:NO];     
    
            [self.view addSubview:v2];
            [segment setSelectedSegmentIndex:1];
    }
    

    }

    hope this help you.

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

Sidebar

Related Questions

- (void)viewDidLoad { [super viewDidLoad]; UIView *myView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 250, 100, 100)];
- (void)viewDidLoad { checkingOption = [[UIView alloc] initWithFrame:CGRectMake(45, 250, 17, 15)]; checkingOption.backgroundColor = [UIColor
I have created several UI elements in the viewDidLoad method. I want to change
I use the following code to add cocos2d scene to a viewcontroller - (void)viewDidLoad
I've create a subview using following code: -(void) viewDidLoad { CGRect subviewRect = CGRectMake(0,
I have a UIView and UIButton (declared in viewDidLoad: method of RootViewcontroller. ). UIView
In my UIViewController's viewDidLoad method I instance a UIImageView instance called stage: stage =
In my view controller's -viewDidLoad method, I call [myTextField becomeFirstResponder]; This works like a
there is a method called viewDidLoad that execute a code when the view is
I have the following loop in my viewDidLoad: for(int i=1; i<[eventsArray count]; i++) {

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.