objective-c - Objective-C:虽然可以完美编译,但应用程序仅运行一次

标签 objective-c crash alert viewcontroller

我创建了一个可以正常编译的应用程序,但是当我再次尝试播放时,模拟器崩溃了,我不知道为什么。我的代码中的相关部分如下:

iFocus2AppDelegate.m


- (void) flipToGameScreen:(NSInteger *)aMode aLevel:(NSInteger*)aLevel 
{
    NSInteger *myMode = aMode;
    NSInteger *myLevel = aLevel;

    GameScreenViewController *aGameScreenView = [[GameScreenViewController alloc] initWithNibName:@"GameScreen" mode:myMode level:myLevel bundle:nil];
    [self setGameScreenViewController:aGameScreenView];
    [aGameScreenView release];
    gameScreenViewController.view.frame =[[UIScreen mainScreen] applicationFrame];

    //animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache: YES];
    [viewController.view removeFromSuperview];
    [self.window addSubview:[gameScreenViewController view]];
    [UIView commitAnimations];      

 }


GameScreenViewController.m


- (id)initWithNibName:(NSString *)nibNameOrNil mode:(NSInteger *)myMode level:(NSInteger *)myLevel bundle:(NSBundle *)nibBundleOrNil 
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        // Custom initialization.
        self.selectedMode = myMode;
        self.selectedLevel = myLevel;

    }
    return self;
}

- (void) finished
{   
    [myTimer invalidate];
    myTimer = nil;
    [myTimer release];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"GameOver"
                 message:@"Do Something"
                 delegate:self
                 cancelButtonTitle:nil
                 otherButtonTitles:nil];
    [alert addButtonWithTitle:@"Play Again"];
    [alert addButtonWithTitle:@"Show HiScores"];
    [alert addButtonWithTitle: @"Setup New Game"];

    [alert show];
    [alert release];
}

- (void) alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        //PlayAgain
        iFocus2AppDelegate *mainDelegate = (iFocus2AppDelegate *)[[UIApplication sharedApplication] delegate];
        [mainDelegate flipToGameScreen:selectedMode aLevel:selectedLevel];
        [iFocus2AppDelegate release];

    }
    if  (buttonIndex == 1)
    {
        //scores
        iFocus2AppDelegate *mainDelegate = (iFocus2AppDelegate *)[[UIApplication sharedApplication] delegate];
        [mainDelegate flipToHiScores];
        [iFocus2AppDelegate release];
    }
    if  (buttonIndex == 2)
    {
        //setings
        iFocus2AppDelegate *mainDelegate = (iFocus2AppDelegate *)[[UIApplication sharedApplication] delegate];
        [mainDelegate flipToGameSettings];
        [iFocus2AppDelegate release];
    }
}

我粘贴了这两部分,因为我认为GameScreenViewController特别有问题,因为它第二次进入该屏幕时会崩溃(任何其他屏幕翻转(即从警报到HiScores)都可以使用。您可能需要其他代码,将不胜感激。

(编辑):根据要求,控制台显示如下内容...

(再次编辑):以前粘贴的代码不是真正的部分;即使我已经阅读了所有答案,但在崩溃时,我在控制台中返回的唯一代码是“GDB:在Build&Debug中时,程序收到信号:“EXC_BAD_ACCESS”。

最佳答案

在某个地方,有人试图创建GameScreenViewController,但是省略了选择器bundle:initWithNibName:mode:level:bundle:部分。基于回溯,它似乎在您的iFocus2AppDelegate的flipToGameScreen:aLevel:方法中,尽管我在那儿看不到它。如果使用旧版本的类,则可以尝试清理项目。

关于objective-c - Objective-C:虽然可以完美编译,但应用程序仅运行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8649259/

相关文章:

delphi - Delphi 中的 MAPI - 工作但在发送邮件后崩溃

ios - Swift - 在打开下一个 View 之前添加加载警报

iOs - 无法识别的选择器发送到 TextAction 上的实例

iphone - 向 Objective-C 和 C 代码添加过程标签

c++ - 时代计算器的筛子—遇到内存问题并崩溃,数字> = 1,000,000

iOS - 为自定义键盘播放 Tock 声音

iphone - nsdate 转换的问题

ios - Firebase 更改显示在谷歌登录警报上的应用程序名称?

objective-c - NSBezierPath 上的剥离描边

ios - 匹配当前日期到对象日期的位置通知