Кнопка UIActionSheet не загружает новый вид - PullRequest
0 голосов
/ 10 марта 2012
-(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 без загрузки нового вида.
Я что-то здесь не так делаю?

Ответы [ 2 ]

4 голосов
/ 10 марта 2012

Вам нужно actionSheet.delegate = self; в вашем displayActionSheet method В противном случае 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__);
}
1 голос
/ 10 марта 2012

Убедитесь, что вы добавили делегата в свой интерфейс

@interface mainviewcontroller : UIViewController <UIActionSheetDelegate> {

}

(РЕДАКТИРОВАТЬ) А затем измените делегата на себя

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