Wednesday, May 29, 2013

UIActionSheet buttonTitleAtIndex example in Objective C (iOS).

UIActionSheet buttonTitleAtIndex

Returns the title of the button at the specified index.

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex

Parameters
buttonIndex
The index of the button. The button indices start at 0.

Return Value of [UIActionSheet buttonTitleAtIndex]
The title of the button specified by index buttonIndex.

UIActionSheet buttonTitleAtIndex example.

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

Example of [UIActionSheet buttonTitleAtIndex].
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {


[BT_debugger showIt:self theMessage:@"!!!action sheet callecd!!!"];

NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

//quit only used if no finished or reward screen present
if([buttonTitle isEqual:NSLocalizedString(@"quit", @"Quit")]){

// if no finish screen then send back to rootviewcontroller
[self.navigationController popToRootViewControllerAnimated:YES];
[BT_debugger showIt:self theMessage:@"Quit tapped"];
}


//show reward
if([buttonTitle isEqual:NSLocalizedString(@"quizShowReward", @"Show Reward")]){
[self showQuizRewardScreen];
[BT_debugger showIt:self theMessage:@"Show Reward Tapped"];
}

//show continue
if([buttonTitle isEqual:NSLocalizedString(@"continue", @"Continue")]){
[self showFinishScreen];
[BT_debugger showIt:self theMessage:@"Continue Tapped"];
}

//show game center
if([buttonTitle isEqual:NSLocalizedString(@"Game Center", @"Game Center")]){
[BT_debugger showIt:self theMessage:@"game center tapped"];
[self showGameCenter];

}
}

UIActionSheet buttonTitleAtIndex example.
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

//quit
if([buttonTitle isEqual:NSLocalizedString(@"quit", @"Quit")]){
[self navLeftTap];
}

//show reward
if([buttonTitle isEqual:NSLocalizedString(@"quizShowReward", @"Show Reward")]){
[self showQuizRewardScreen];
}

//show continue
if([buttonTitle isEqual:NSLocalizedString(@"continue", @"Continue")]){
[self showFinishScreen];
}

//try again
if([buttonTitle isEqual:NSLocalizedString(@"quizTryAgain", @"Try Again")]){
[self startQuiz];
}
}

End of UIActionSheet buttonTitleAtIndex example article.