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; 
    }   
} 
} 
    } 

Devanagari 단추를 누르면 새로운보기가로드되지만 새보기를로드하지 않고 단순히 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'으로 설정했기 때문에 컨트롤러에도 설정해야합니다. 언급 할만한 가치가 있습니다. –