从flipside获取UISegmentedController值

时间:2011-03-28 23:23:24

标签: iphone objective-c cocoa-touch

如果你只有SDK提供的实用程序模板,在flipsideview上有一个分段控制器,带有几个十进制值段,并且你想获取主视图的当前值,那么最好的方法是什么?感谢您抽出宝贵时间回答!

MainViewController.m

-(void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
    [self dismissModalViewControllerAnimated:YES];

    //This does get the value, but only by going to the flipside first then back to the mainview.
    SegValueLabel.text = [controller.RiseSegmentedControl titleForSegmentAtIndex:controller.RiseSegmentedControl.selectedSegmentIndex];
}

-(IBAction)CalculateButton:(id)sender{
    //Need to get the value of segmented control from FlipSideView and assign it a variable.
}

1 个答案:

答案 0 :(得分:1)

确保分段控制器映射到flipside视图中的IBOutlet属性。如果您使用Apple实用程序应用程序模板,您将看到FlipsideViewControllerDelegate由MainViewController实现。如果您不使用它,请使用它作为示例创建项目。在MainView中实现flipsideViewControllerDidFinish:方法并使用它来获取类似这样的属性:

flipsideController.segmentedControlProperty.selectedIndex;

或者如果你想要标题:

[flipsideController.segmentedControlProperty titleForSegmentAtIndex:flipsideController.segmentedControlProperty.selectedIndex];