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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:49:02+00:00 2026-05-28T05:49:02+00:00

I have an app that has two viewcontrollers Viewcontroller and OptionsViewController. Viewcontroller is the

  • 0

I have an app that has two viewcontrollers Viewcontroller and OptionsViewController. Viewcontroller is the initial viewcontroller then if I click a button I have a modal segue to optionsviewcontroller.

There in optionsviewcontroller I have I UISegmented viewcontroller created from the storyboard which is linked to an outlet (UnitsSegmentedControl) and I want to be able to tell the segmented control which segment should be selected by default when OptionsViewController loads.

In my Viewcontroller I wrote a method:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    OptionsViewController *ovc=[segue destinationViewController];
    ovc.delegate=self;
    [ovc.UnitsSegmentedControl setSelectedSegmentIndex:1];
}

the thing is when OptionsViewController loads the view the selected index is 0 as by default. I don’t get any error message or something.

I’m using Xcode 4.2. I think It might be some option I can change in storyboard to make the UISegmentedControl to be able to set default selected index. I don’t know what else could be causing that.

EDIT:
I figured out that if I write :

[ovc.UnitsSegmentedControl setSelectedSegmentIndex:1];

inside OptionsViewController method viewdidload everything works fine. Why am I not able to do it from the prepare for segue method?

  • 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-28T05:49:03+00:00Added an answer on May 28, 2026 at 5:49 am

    The segmented control does not exist until the OptionsViewController is loaded which is why you cannot set the selected segment in the prepareForSegue method of you ViewController. Review the UISegmentedControl Class Reference reveals that there is no way to set a default state:

    “The default value is UISegmentedControlNoSegment (no segment selected) until the user touches a segment. Set this property to -1 to turn off the current selection. UISegmentedControl ignores this property when the control is in momentary mode. When the user touches a segment to change the selection, the control event UIControlEventValueChanged is generated; if the segmented control is set up to respond to this control event, it sends a action message to its target.”

    Setting the selectedSegmentIndex in the viewDidLoad method of your OptionsViewController is the correct way to set a default value the view controller.

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

Sidebar

Related Questions

In my iPhone app I have two viewControllers: viewController1 has a tableView that shows
I have an app that has a centre view with two views off to
I have an app that has a TableView, NavigationView and TabBar running together. There
i have an app that has a few checkboxes in the settings and then
I have an app that has two buttons – one for email & one
I have a simple user registration page in my rails app that has two
I have a rails app that has two models one is vender and the
I've created a custom button in my Android app that has basically two different
I have an iphone app that has been downloaded in the last two months
Have an app that has listings - think classified ads - and each listing

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.