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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:56:07+00:00 2026-05-30T10:56:07+00:00

I have added custom Badge on UISegmentControl. In Xcode 4.0.2 SDK 4.3 its working

  • 0

I have added custom Badge on UISegmentControl. In Xcode 4.0.2 SDK 4.3 its working fine. But in Xcode 4.2 SDK 5.0 custom badge is not shown when another item is selected. I dont know why this happens? I’m using following code for IOS 4.3 Xcode 4.0.2:

- (void)viewDidLoad {
    [super viewDidLoad];

    super.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallpaper.png"]];
    NSLog(@"Root View Loaded");

    segmentedControl = [[UISegmentedControl alloc] initWithItems:
                                            [NSArray arrayWithObjects:
                                             @"Home",@"Surveys",@"Results",@"Create",@"Settings",
                                             nil]];
    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    segmentedControl.frame = CGRectMake(0, 0, 310, 40);
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    segmentedControl.tintColor = [UIColor darkGrayColor];
    segmentedControl.momentary = NO;
    segmentedControl.highlighted = YES;

    segmentedControl.selectedSegmentIndex = 0;

    UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];

    NSArray *segmentBarArray = [NSArray arrayWithObjects:
                                segmentBarItem,nil];

    [[self appDelegate] setSegmentedControl:segmentedControl];
    [[self appDelegate] setSegmentBarArray:segmentBarArray];

    [self setToolbarItems:[[self appDelegate] segmentBarArray] animated:NO];

    [[self navigationController] setToolbarHidden:NO animated:YES];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    self.navigationController.toolbar.tintColor = [UIColor blackColor];

    int surveycount = [[self appDelegate] getUnreadSurveyCount];
    surveyCountBadge = [CustomBadge customBadgeWithString:[NSString stringWithFormat:@"%d",surveycount]];
    [surveyCountBadge setFrame:CGRectMake(105, -10, surveyCountBadge.frame.size.width, surveyCountBadge.frame.size.height)];

    [segmentedControl addSubview:surveyCountBadge];    
    if (surveycount == 0) {
        [surveyCountBadge setHidden:YES];
    }else{
        [surveyCountBadge setHidden:NO];
    }
}
-(void)segmentAction:(id) sender{
    UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
    NSLog(@"selected index is %d",segmentedControl.selectedSegmentIndex);

    if (segmentedControl.selectedSegmentIndex == 0) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    } else if(segmentedControl.selectedSegmentIndex  ==1){
        surveyForMeViewController = [[SurveyForMeView alloc] initWithNibName:@"SurveyForMeView" bundle:nil];
        [self.navigationController pushViewController:surveyForMeViewController animated:YES];

    } else if(segmentedControl.selectedSegmentIndex  ==2){
        resultViewController = [[ResultView alloc] initWithNibName:@"ResultView" bundle:nil];
        [self.navigationController pushViewController:resultViewController animated:YES];

    } else if (segmentedControl.selectedSegmentIndex ==3) {
        newSurveyViewController = [[NewSurveyView alloc] initWithNibName:@"NewSurveyView" bundle:nil];
        [self.navigationController pushViewController:newSurveyViewController animated:YES];

    } else if (segmentedControl.selectedSegmentIndex ==4) {
        settingsViewControlle = [[SettingsView alloc] initWithNibName:@"SettingsView" bundle:nil];
        [self.navigationController pushViewController:settingsViewControlle animated:YES];
    }


}

Any thing else should I mention in 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-30T10:56:08+00:00Added an answer on May 30, 2026 at 10:56 am

    You are adding a subview to a segmentedControl. As you don’t know how the system redraws the control when another item is selected, you cannot say if your view will be removed or not. Let the control, button or segmentedControl do its work and if you want to add a badge, add it as a subview of its parent.

    [surveyCountBadge setFrame:CGRectMake(105.0f+segmentedControl.frame.origin.x,
       -10.0f+sementedControl.frame.origin.y, surveyCountBadge.frame.size.width, 
        surveyCountBadge.frame.size.height)];
    
    [[segmentedControl superView] addSubview: surveyCountBadge];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in a MySQL database. I have added a custom field to
I have added hashtable(ID and Name) as custom property for each item (Node). The
I have added a custom action to the CustomList type. For testing purposes I
In Silverlight 3.0 I have added a custom behavior to some UIElement in Code
I am using jquery validation plugin for form validation. I have added a custom
I have a list within Sharepoint, using a custom new form I have added
I'm trying to make a custom infowindow. Version = 2. I have added my
If have created a custom role within SqlServer which I added to the db__denydatareader
I have a custom list, and I've added a 'Page Image' field by clicking
I have a few custom UITableViewCells - http://img11.imageshack.us/i/customfacilitiescell.png/ which are added to this UIViewController

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.