2012-03-09 3 views
0

UIActionSheet의 버튼을 다음 코드를 사용하여 뷰 변경을 수행하려고합니다.뷰를 표시 할 UIActionSheet 버튼

-(void)displayActionSheet:(id)sender 
    { 

actionSheet = [[UIActionSheet alloc] 
           initWithTitle:nil 
           delegate:nil 
           cancelButtonTitle:@"Cancel" 
           destructiveButtonTitle:nil 
           otherButtonTitles:@"Devanagari", @"English", nil]; 

actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; 

[actionSheet showInView:self.view ]; 

[actionSheet release]; 

} 

이 코드를 수정하여 Devanagari와 English 버튼을 각각의 개별보기로 연결하려면 어떻게해야합니까?

답변

1

덜 혼란스럽게 만들기 위해 actionSheet의 이름을 actionSheet 이외의 이름으로 지정하는 것이 좋습니다. 덜 혼란

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

switch (buttonIndex) 
      { 
       case 0: 
       { 
      DevanagariViewController *controller1 = [[DevanagariViewController alloc] initWithNibName:@"DevanagariViewController" bundle:nil]; 
[self presentModalViewController:controller1 animated:NO]; 
       NSLog(@"DevanagariViewController"); 
       break; 
       } 


       case 1: 
       { 
          EnglishViewController *controller2 = [[EnglishViewController alloc] initWithNibName:@"EnglishViewController" bundle:nil]; 
[self presentModalViewController:controller2 animated:NO]; 
       NSLog(@"EnglishViewController"); 
       break; 
       } 


      } 


     } 
+2

뿐만 아니라은,'actionSheet == actionSheet' 항상 TRUE ''로 평가한다. 아마도 매개 변수 이름을 변경하거나'self-> actionSheet'를 사용하거나 속성으로 만들고'self.actionSheet'를 사용해야합니다. – Sulthan

2
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex]; 
    if([title isEqualToString:@"Devanagari"]) { 
     //Code if Devanagari button is pressed 
    } 
    if([title isEqualToString:@"English"]) { 
     //Code if English button is pressed 
    } 
}