首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIAlertView到UITableViewController

UIAlertView到UITableViewController
EN

Stack Overflow用户
提问于 2012-07-30 15:33:13
回答 4查看 266关注 0票数 0

当我在UIAlertView上按下'OK‘按钮时,我想让它返回到UITableViewController,但当我点击它时,它不会返回。

QuizViewController.h

代码语言:javascript
运行
复制
@interface QuizViewController : UIViewController <UIAlertViewDelegate> { 
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

@end

QuizViewController.m

代码语言:javascript
运行
复制
-(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]; 
}
EN

Stack Overflow用户

发布于 2012-07-30 15:37:28

您不应该在.h文件中声明委托方法,如:-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

取而代之的是在alertView中使用delegate:self,如下所示:

代码语言:javascript
运行
复制
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Results" message:[[NSString alloc] initWithFormat:@"Your total score will be %i!", myScore]
                                                    delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

并在.h文件中声明如下

代码语言:javascript
运行
复制
@interface QuizViewController : UIViewController<UIAlertViewDelegate>

然后单击button.index=0在您的委托方法中使用[self.navigationController presentModalViewController:quizTable animated:YES];

票数 0
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11717111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档