2014-09-10 1 views
1

다른보기로 밀어 넣기 작업을 수행하는 단추가 있습니다. 내 목표는 선택한 세그먼트에 따라 다른보기를 열려면이 단추를 만드는 것입니다. 예 : '요청'이라는 버튼이 있고 '피자 소금'과 '스위트 피자'라는 두 세그먼트가있는 컨트롤 세그먼트가 있습니다. 세그먼트에서 "Pizza Salt"를 선택한 다음 "Request"버튼을 즉시 클릭하면 "Salt Pizza"메뉴에 대한보기가 열리고 "Sweet Pizza"가 선택됩니다. "Sweet Pizza"메뉴로 다른보기를 엽니 다.분할 된 컨트롤을 사용하여 단추 동작을 변경하는 방법

참고 : 이미 두 개의 컨트롤러가 뷰와 함께 준비되어 있습니다.

어떤 코드를 사용합니까?

내 코드 :

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

- (IBAction)pushToNextView:(id)sender { 


} 

답변

0

요청 버튼을 눌러시 :

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

답변을 주셔서 감사합니다. 그러나 내가 원하는 것은 : "짠"세그먼트를 선택할 때, 버튼을 클릭 할 때 "소금기가있는"보기를 입력하는 동작 버튼을 변경합니다. 세그먼트를 선택하면보기로 자동 전환됩니다. –

+0

그 답이 맞습니다. 먼저 세그먼트를 선택한 다음 동작 버튼을 누르면 위의 코드를 사용하여 올바른보기 컨트롤러를 푸시합니다. – freshking

+0

Nooo, 나 이해 못해. 예를 들어, "Salty"를 선택하면 "Delivery"버튼을 클릭하여보기를 밀어야 할 필요가 있습니다. [Salty] | [Sweet] 세그먼트에서 클릭 한 후 자동으로 푸시되지 않습니다. –

2

사용 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에서속성을 사용합니다..

관련 문제