2011-02-05 31 views

回答

6

您將需要使用其中的兩個,使用selectedSegmentIndex屬性。如果當您從一個控件獲取操作時,將其他控件的屬性值設置爲-1,它將有效地爲您提供兩行中的六個按鈕組,這兩個按鈕似乎作爲一個組鏈接在一起。

+1

智能和簡單的方法來做到這一點。謝謝。我可能只是補充說,你可以使用`[self.orderOptionsSegmentedControl addTarget:self action:@selector(disableOtherSegmentedControl :) forControlEvents:UIControlEventValueChanged];`來檢測一個`UISegmentedControl`的選擇,我只是將代碼放在一個希望有人需要它的新答案。 – Ali 2013-09-23 09:43:28

1

只需將代碼添加到@Adam埃伯巴赫的回答是:

viewDidLoad

[self.orderOptionsSegmentedControl1 addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged]; 
[self.orderOptionsSegmentedControl2 addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged]; 

然後實現disableOtherSegmentedControl

- (void) disableOtherSegmentedControl:(id)sender 
{ 
    if (sender == self.orderOptionsSegmentedControl1) 
    { 
     self.orderOptionsSegmentedControl2.selectedSegmentIndex = -1; 
    } 

    else if (sender == self.orderOptionsSegmentedControl2) 
    { 
     self.orderOptionsSegmentedControl1.selectedSegmentIndex = -1; 
    } 
}