2012-03-09 10 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と英語のボタンをそれぞれ別々のビューにリンクするにはどうすればよいですか?

答えて

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 
    } 
} 
関連する問題