2013-03-19 9 views
0

내 uiactions 시트에 Uiswitch를 구현하고 있는데, 내가 원하는 위치에 성공적으로 배치했지만 사용할 방법은 없습니다. 여기 내 코드는 다음과 같습니다.UIACS 시트에있는 UISwitch에서 답변을 얻는 방법

switchButton = [[UISwitch alloc] init]; 
[mySheet addSubview:switchButton]; 
[mySheet showInView:self.view]; 

UILabel *instruction = [[UILabel alloc] init]; 
[instruction setBackgroundColor:[UIColor clearColor]]; 
[instruction setText:@"Daily"]; 
[mySheet addSubview:instruction]; 

// get the dimension of the sheet to position the switch 
CGSize parentSize = mySheet.frame.size; 
CGRect rect = switchButton.frame; 
rect.origin.x = parentSize.width/2.0 - rect.size.width + 90; 
rect.origin.y = parentSize.height - rect.size.height + 90 ; 
switchButton.frame = rect; 


//get the dimension of the sheet to possition the label 
rect.origin.x = parentSize.width/2.0 - rect.size.width -20; 
rect.origin.y = parentSize.height - rect.size.height + 90 ; 
instruction.frame = rect; 

스위치 버튼을 iboutlet으로 초기화했습니다. 액션 시트의 기능에서 나는 이것을하려고합니다. 그것을 위해 - "(IBAction를) (SECURITY) 기능을 비활성화를"하지만 난 이런 짓을 할 때 내가 함께이 링크 가져올 수 없습니다

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:  (NSInteger)buttonIndex{ 



    switch (buttonIndex) { 
     case 0: 
     { 

      NSLog(@"Yes Button is working"); 
     } 
      break; 
     case 1: 
     { 

      if(switchButton.on){ 

      NSLog(@"IS on ?"); 
     } 
      else { 

     NSLog(@"Is off?"); 

     } 
     } 
     default: 
      break; 
    } 

It is all set

** IMP 나는 또한 내가 만든 한 가지 더에 시도했습니다 내 스위치 **

+0

스위치를 사용할 수 없거나 스위치를 사용할 수 없거나 올바른 값을 읽을 수 없다는 뜻입니까? – M0rph3v5

+0

iam이 switch 문을 통해 catch하려고 할 때 실제로 Uiactionsheet에 코드가 표시되면 실제로 읽지 않습니다. S –

답변

1

다음 코드

switchButton = [[UISwitch alloc] init]; 

[switchButton addTarget:self action:@selector(setState:) forControlEvents:UIControlEventTouchUpInside]; 
+0

아, 선생님, 대단히 감사합니다. :). –

+1

[스위치 isOn]/on 속성을 사용할 때 스위치에서 입력 벌금을 읽을 수 있어야합니다. 코드에 문제가있을 수 있습니다. 스위치가 아무렇지도 않게 (독서 시점에) 있습니까? – M0rph3v5

0

IBOutlet으로 설정하면 프로그래밍 방식으로 스위치를 생성하기 때문에 아무 것도하지 않습니다. 정말 간단한 단추 선택을 위해 설계된 UIActionSheet를 사용하는 대신 모달 식으로 표시하는 자체 UIViewController (인터페이스 작성기에서 디자인)를 만들어야합니다.

그러나 UIActionSheet를 계속 사용하는 경우 스위치를 변경하면 이벤트를 잡기 위해 UISwitch를 만들 때 UISchange에 'addTarget'을 호출 할 수 있습니다.

+0

그래서 사용자 정의보기로 이동해야합니까? –

0

은 또한 당신이 UIActionSheet에 하위 뷰를 추가하기 전에 UISwitch보기에 대한 태그 값 (예 : 6)을 설정할 수 있습니다 도움이 될 것입니다. 방법 clickedButtonAtIndex[(UISwitch *)[actionSheet viewWithTag:6] isChecked]

0

를 사용하여이 값을 확인할 수 있습니다 해고 그런 때 당신은 당신이 플래그를 확인할 수 있습니다 ActionSheet에서 UISwitch

[mySwitch addTarget:self action:@selector(switchChanged) forControlEvents: UIControlEventTouchUpInside]; 
-(void)switchChanged{ 
    if(switchOn){ 
    switchOn=NO; 
    } 
    else { 
    switch=YES; 
    } 
} 

에 대한 값을 설정할 수 BOOL 플래그를 가질 수 swithcOn