2012-03-09 36 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 button不加載新視圖

回答

4

你需要在你的displayActionSheet method否則UIActionSheetDelegate方法actionSheet.delegate = self;不會被調用。

或者在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

added actionSheet.delegate = self;但仍然沒有顯示視圖改變,太多委託:自我在初始化 – user1120133 2012-03-09 22:26:51

+0

委託方法應該是' - (空)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger的)buttonIndex'(注意小寫),你可以把一個斷點然後確認該方法是否被調用? – FluffulousChimp 2012-03-09 22:30:11

+0

貌似這個方法不會被調用我定義這個方法正下方的mainviewcontroller – user1120133 2012-03-09 22:33:54

1

確保您已經添加了代表在接口

@interface mainviewcontroller : UIViewController <UIActionSheetDelegate> { 

} 

(EDIT)然後委託改變自我

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

他把委託'nil'他的代碼示例中,所以他還需要到設置爲自己的控制器,以及。值得一提。 – 2012-03-09 22:49:52