如何在UISegmentedControl中显示数据?

时间:2014-02-08 16:45:01

标签: ios iphone database uiviewcontroller viewcontroller

我有一个分段控件(2段),我想在点击每个段时显示数据

如果segmentcontrol.selectedSegmentIndex == 0 然后显示来自http://arproject.site90.com/jsonbuilding.php

的数据

如果segmentcontrol.selectedSegmentIndex == 1 然后显示来自http://arproject.site90.com/jsonshop.php

的数据

如何在分段控制中显示数据?

1 个答案:

答案 0 :(得分:0)

以下是我项目中的代码,必须处理您的要求。我也是新手,需要这个概念的帮助,这里有一个帮助我的链接,以防我的代码不够清晰:http://iphonedevsdk.com/forum/tutorial-discussion/29597-uisegmentedcontrol-tutoria.html

- (IBAction)segmentedControlPressed:(id)sender {
if (self.measurementSegmentedControl.selectedSegmentIndex ==0) {
    self.waterLabel.text = @"Water (mL)";
    self.ratioLabel.text = @"Ratio (mL/g)";
    self.coffeeLabel.text = @"Coffee (g)";
    self.metricLabel.textColor = [UIColor whiteColor];
    self.metricLabel.shadowColor = [UIColor colorWithRed:.31 green:.31 blue:.31 alpha:1];
    self.metricLabel.shadowOffset = CGSizeMake(1, 1);
    self.usLabel.textColor = [UIColor colorWithRed:.71 green:.71 blue:.71 alpha:1];
    self.usLabel.shadowColor = [UIColor colorWithRed:.31 green:.31 blue:.31 alpha:1];
    self.usLabel.shadowOffset = CGSizeMake(1, 1);
    }

if (self.measurementSegmentedControl.selectedSegmentIndex ==1) {
    self.waterLabel.text = @"Water (cups)";
    self.ratioLabel.text = @"Ratio (cups/Oz)";
    self.coffeeLabel.text = @"Coffee (Oz)";
    self.usLabel.textColor = [UIColor whiteColor];
    self.usLabel.shadowColor = [UIColor colorWithRed:.31 green:.31 blue:.31 alpha:1];
    self.usLabel.shadowOffset = CGSizeMake(1, 1);
    self.metricLabel.textColor = [UIColor colorWithRed:.71 green:.71 blue:.71 alpha:1];
    self.metricLabel.shadowColor = [UIColor colorWithRed:.31 green:.31 blue:.31 alpha:1];
    self.metricLabel.shadowOffset = CGSizeMake(1, 1);
    }
}

这可以控制此分段控件: Which enables control for this segmented control:

希望这有帮助,祝你好运!