分段控制问题

时间:2009-05-04 10:45:10

标签: iphone

我有一个UISegmentControl在我的视图中有2个段,问题是我选择的任何段,它将在我的selectedSegmentIndex属性中返回1,因为我希望它保留在第一个视图时选择段0,我使用的事件在我的segmentcontrol中是valueChanged,函数将调用如下所示:     - (无效)segmentSelect:(ID)发送方{

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];
}

} 任何人都可以说出了什么问题?

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

 -(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");
    } 
}