当我按下“确定”按钮时,UIAlertView
我希望它返回, UITableViewController
但当我单击它时,它不会返回。
QuizViewController.h
:
@interface QuizViewController : UIViewController <UIAlertViewDelegate> {
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
@end
QuizViewController.m
-(IBAction)buttonWasClicked:(id)sender{
UIButton *resultebutton= (UIButton*)sender;
if (qCount < totalQuestions) {
id prevQuestion = [appDelegate.qs objectAtIndex:qCount-1];
NSString * correctAns = [prevQuestion labelAns];
if ([correctAns isEqualToString:resultebutton.titleLabel.text])
myScore += 5;
NSLog(@"The button title is %@ ", correctAns);
NSLog(@"The button title is %@ ", resultebutton.titleLabel.text);
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Your score so far is %i!", myScore];
theScore.text = finishingStatement;
id nextQuestion = [appDelegate.qs objectAtIndex:qCount];
quizLbl.text = [nextQuestion labelQn];
headerLbl.text = [nextQuestion labelHeader];
[qBtn setTitle:[nextQuestion labelBtn] forState:UIControlStateNormal];
[qBtnB setTitle:[nextQuestion labelBtnB] forState:UIControlStateNormal];
[qBtnC setTitle:[nextQuestion labelBtnC] forState:UIControlStateNormal];
[qBtnD setTitle:[nextQuestion labelBtnD] forState:UIControlStateNormal];
qCount++;
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Results" message:[[NSString alloc] initWithFormat:@"Your total score will be %i!", myScore]
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
QuizTableViewController *quizTable = [self.storyboard instantiateViewControllerWithIdentifier:@"quizTable"];
[self.navigationController presentModalViewController:quizTable animated:YES];
}