2012-03-09 4 views
0
-(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]; 

} 

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

if(actionSheet == actionSheet) 
{ 
switch (buttonIndex) { 

    case 0:{ 

     //Devanagari view display 

     ButtonViewController *controller1 = [[ButtonViewController alloc]init]; 

     controller1.delegate = self; 

     UINavigationController *navigationController = [[UINavigationController alloc] 
                 initWithRootViewController:controller1]; 
     navigationController.navigationBar.tintColor = [UIColor colorWithHue:2.0/12 saturation:2.0 brightness:4.0/10 alpha:1.0]; 

     [self presentModalViewController:navigationController animated:YES]; 

     [navigationController release]; 

     break; 
    }   
} 
} 
    } 

をロードしていないが、それは単に新しいビューをロードせずにUIActionSheetを解雇されます。
ここで何か間違っていますか?UIActionSheetボタンは、新しいビュー

答えて

4

displayActionSheet methodactionSheet.delegate = self;が必要です。そうしないと、UIActionSheetDelegateメソッドは呼び出されません。

また、initメソッドでデリゲートを提供してください。あなたは現在、それをnilに設定しています。

私は、次の作品ていることが確認さ:

- (void)displayActionSheet; 
{ 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self 
                cancelButtonTitle:@"Cancel" 
               destructiveButtonTitle:nil 
                 otherButtonTitles:@"Devanagari",@"English", nil]; 
    [actionSheet showInView:self.view]; 
    [actionSheet release]; 
} 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex; 
{ 
    NSLog(@"%s - Called!",__FUNCTION__); 
} 
+0

が追加されましたactionSheet.delegate = self;それでもまだビューを表示していないのですが、それでもデリゲートを変更しました:セルフinit – user1120133

+0

デリゲートメソッドは ' - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex :(NSInteger)buttonIndex'です。メソッドが呼び出されているかどうかを確認します。 – FluffulousChimp

+0

このメソッドが呼び出されていないようです。私はmainviewcontrollerのdisplayActionSheetメソッドのすぐ下にこのメソッドを定義しました – user1120133

1

はあなたのインターフェイス

@interface mainviewcontroller : UIViewController <UIActionSheetDelegate> { 

} 

(EDIT)にデリゲートを追加したことを確認してください。そして自己

actionSheet = [[UIActionSheet alloc] 
          initWithTitle:nil 
          delegate:self 
          cancelButtonTitle:@"Cancel" 
          destructiveButtonTitle:nil 
          otherButtonTitles:@"Devanagari", @"English", nil]; 
にデリゲートを変更
+0

彼は彼のコードサンプルでデリゲートを 'nil'に設定しましたので、彼のコントローラーにも同様に設定する必要があります。言及に値する。 –

関連する問題