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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:57:41+00:00 2026-05-20T01:57:41+00:00

Hello I’ve tried for 3 weeks to solve this issue and it stumps me.

  • 0

Hello I’ve tried for 3 weeks to solve this issue and it stumps me. What i am trying to do is create a 3 part segment from an array, display it in a view in a certain position, then remove it from view when the “OFF” flag is set. Every thing works except the removal of the segment. It will even commuticate with (pickOne) and display the segment letters in a label. What i can’t get to work is either of the two: setHidden:YES, or removeAllSegments. Any help would be appreciated. Here is my code.

- (void) showSegment {

    int x = 192; 
    int y = 212;

    int w = 125;
    int h = 25;

    SegUnit1 = @"A";
    SegUnit2 = @"B";
    SegUnit3 = @"C";

    threeSegs = [NSArray arrayWithObjects: SegUnit1, SegUnit2, SegUnit3, nil];  
    segSize = [NSArray arrayWithArray:threeSegs];

    UISegmentedControl *heightSC = [[UISegmentedControl alloc] initWithItems:segSize];  

    if ([segmentState_height isEqualToString:@"ON"]) {

        NSLog(@"segmentState_height = %@",segmentState_height); 
        heightSC.frame = CGRectMake(x, y, w, h);    
        heightSC.segmentedControlStyle = UISegmentedControlStyleBar;
        heightSC.selectedSegmentIndex = -1;
        [heightSC addTarget:self
                     action:@selector(pickOne:)
           forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:heightSC];
        [heightSC release]; 
    }   else if ([segmentState_height isEqualToString:@"OFF"]) {

        NSLog(@"segmentState_height = %@",segmentState_height);
        [heightSC setHidden:YES]; // NSLog showing "OFF" but segment will not hide. 
        [heightSC removeAllSegments]; // NSLog showing "OFF" and segment is suppose to dismantle and does not.

    }
}

I know now that i have to “not” create and remove in the same function, and was given a tip on correcting this but I don’t know how to use the tip.

here is what was suggested.

Well, your method is a little confused, since you are trying to both create and hide at the same time. So you might consider splitting that up into separate methods.

In general, it will be along these lines:

Code:

if ([self theControlProperty] == nil)
{
    UISeg... *theControl = [[UISeg alloc] ....];

    [self setTheControlProperty:theControl];

    ...

}

if (shouldHideTheControl)
{
    [[self theControlProperty] setHidden:YES];
}

Any help would be appreciated.

  • 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-20T01:57:42+00:00Added an answer on May 20, 2026 at 1:57 am

    The problem you have is that you’re creating a new UISegmentedControl instance every time that method is called. The first time through, you create an instance and add it as a subview to your view. This apparently works fine, as it should. Then the method returns, and you no longer have any easy way to refer to that instance that you created. When you re-enter -showSegment, you create a different instance, and then hide and/or destroy it. This different instance has no effect whatsoever on the instance that you gave to the view.

    What you need to do is make heightSC an instance variable. Add it to the interface declaration in the header file, then initialize it only once, and hide or modify it as needed subsequently. The key point is that you need to have a reference to the instance of the UISegmentedControl which is being drawn on the screen, a reference that lives outside the method itself that you can use the second, third, fourth, etc time you call that method.

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

Sidebar

Related Questions

Hello can anybody solve this please I'm creating the object in the action class
Hello I'm a trying to learn python, In C++ to read in string from
Hello everyone I'm trying to make a flash uploader. The issue however that has
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello I am using jquery layout plugin from http://layout.jquery-dev.net/ . my options are following:
Hello I have a Problem with some Buttons I would like to create a
Hello everyone i need to convert this code to a function with 2 parameters
hello I am using zend framework and i am trying to combine it with
Hello guys I am working on silverlight and I have issue regarding on database

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.