tags:

views:

435

answers:

1

i have a UISegmentControl which have 2 segment in my view,the problem is whatever segment i have choosed, it will return 1 in my selectedSegmentIndex property since i want it remain at the first view when select segment 0,the event i used in my segmentcontrol is valueChanged, and the function will be call as show below: -(void)segmentSelect:(id)sender{

NSInteger select=[sender selectedSegmentIndex];

if(select==0){

 NSLog(@"this is 0");

}
else{
 NSLog(@"this is 1");
 infoViewController *viewController = [[infoViewController alloc]initWithNibName:@"infoView" bundle:[NSBundle mainBundle]];
 [[self navigationController] pushViewController:viewController animated:YES];
 [viewController release];
}

} can anybody tell what goes wrong?

+2  A: 

try something like this:

 -(void)segmentSelect:(id)sender{
    UISegmentedControl* segmentedControl = sender;

    switch ([segmentedControl selectedSegmentIndex]) {
            case 0:
          NSLog(@"this is 0");
          break;
         case 1:
          NSLog(@"this is 1");
                            //push the controller
          break;
            default:
          NSLog(@"this is unexpected");
    } 
}
Benjamin Ortuzar
i tried your code but it returned the same thing,it jus weird.no matter which segment i selected, it will always push the viewcontroller
Can u add to the question the code that contains the Segmented Control?, maybe we are looking in the wrong place.
Benjamin Ortuzar