Note that there are some explanatory texts on larger screens.

plurals
  1. POSegment control not getting selected or highlighted
    primarykey
    data
    text
    <p>ViewDidLoad</p> <pre><code>v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; v2= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; </code></pre> <p>// then i add componants to both these views.</p> <p>for v1, i add several textfileds, and button for v2, i add several labels, and a image</p> <p>and in the same viewDidLoad method i add a segment controller to the navigationcontroller;</p> <pre><code>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 ; </code></pre> <p>Now in the ;</p> <pre><code>-(void)segmentclicked:(id)sender { if ((((UISegmentedControl *)sender).selectedSegmentIndex) == 0 ) { [v1 setHidden:YES]; [v2 setHidden:NO]; [self.view addSubview:self.v1]; [loginSignupSegment setSelectedSegmentIndex:0]; &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; [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]; &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; [segmentControllerView addSubview:segment]; self.navigationItem.titleView = segmentControllerView; }} </code></pre> <p>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 <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> in the code.</p> <p>How can i solve this ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload