Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用分段控件更改按钮操作_Ios_Iphone_Xcode_Uisegmentedcontrol_Segment - Fatal编程技术网

Ios 如何使用分段控件更改按钮操作

Ios 如何使用分段控件更改按钮操作,ios,iphone,xcode,uisegmentedcontrol,segment,Ios,Iphone,Xcode,Uisegmentedcontrol,Segment,我有一个按钮,它有一个动作,可以推动另一个视图。我的目标是使此按钮根据选定的线段打开不同的视图。例如:我有一个名为“请求”的按钮,有一个包含两个段的控制段,分别称为“比萨盐”和“甜比萨”。例如,当在段中选择“比萨盐”,然后立即单击“请求”按钮时,我想打开“盐比萨”菜单的视图,并选择“甜比萨”我想用按钮打开另一个“甜比萨饼”菜单的视图 注意:我已经准备好了两个带有视图的控制器 我使用什么代码 我的代码: - (IBAction)changeButtonCode:(id)sender { i

我有一个按钮,它有一个动作,可以推动另一个视图。我的目标是使此按钮根据选定的线段打开不同的视图。例如:我有一个名为“请求”的按钮,有一个包含两个段的控制段,分别称为“比萨盐”和“甜比萨”。例如,当在段中选择“比萨盐”,然后立即单击“请求”按钮时,我想打开“盐比萨”菜单的视图,并选择“甜比萨”我想用按钮打开另一个“甜比萨饼”菜单的视图

注意:我已经准备好了两个带有视图的控制器

我使用什么代码

我的代码:

- (IBAction)changeButtonCode:(id)sender {
    if (_firstSegmentSixthView.selectedSegmentIndex == 0);
}

- (IBAction)pushToNextView:(id)sender {


}

按下请求按钮后:

if (_firstSegmentSixthView.selectedSegmentIndex == 0) //salty
{
    ViewController1 *vc1 = [[ViewController1 alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
else if (_firstSegmentSixthView.selectedSegmentIndex == 1) //sweet
{
    ViewController2 *vc2 = [[ViewController2 alloc] init];
    [self.navigationController pushViewController:vc2 animated:YES];
}

使用此方法在UIsegmentControl的不同按钮上执行操作:

- (IBAction) segmentControlBtnAction:(id)sender
{
    UISegmentedControl* segmentControl = (UISegmentedControl *)sender;
    int index = [segmentControl selectedSegmentIndex];

    switch(index)
    {
        case 0: // Perform action on first button of segment controller 
                break;
        case 1: // Perform action on second button of segment controller 
                break;
        case 2: // Perform action on second button of segment controller 
                break;
        default 
               break;

    }
}

将此方法与
xib
中的
UISegmentControl
连接,使用属性
“值已更改”

感谢您尝试回答,但我想要的是:当我选择“salty”段时,更改操作按钮,当我单击按钮时,进入“salty”视图。我不希望当我选择一段时,自动切换到视图。这正是答案。你首先选择一个片段,然后按下动作按钮,你用上面的代码来按下正确的视图控制器。看:我有一个名为“请求”的按钮和一个名为:[Salty]|[Sweet]的控制段,例如,当我选择“Salty”时,我需要点击按钮“Delivery”来推动视图,而不是在点击段后自动推动。现在请仔细听:上面的代码是针对您的“Delivery”按钮和##不是针对您的段控制!哇,我旅行的时候头脑很冷静。对不起,谢谢你的回答!这是整天呆在目标c煎炸的结果哈哈,再次抱歉,老兄!