xcode application unable to end correctly

I am new to xcode and apple.  I wrote a simple application and it works fine.  It is a couple of moving balls that when collides with player ball it should end the game.  It does end the game but when I select the dismiss button it crashes.  I am sure I am missing something simple.  Any help would be appreciated.  thank you


Open in new window


#import "PugEscape1ViewController.h"

@interface PugEscape1ViewController ()

@end

@implementation PugEscape1ViewController

- (void)viewDidLoad{
   
   
        [super viewDidLoad];
        //(x speed, y speed)
        pos = CGPointMake(2.0,3.0);
        // Do any additional setup after loading the view, typically from a nib.
    }
   - (IBAction)start {
        [startbutton setHidden:YES];
        randomMain = [NSTimer scheduledTimerWithTimeInterval:(0.03) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
       
       
   }
  -(void)onTimer {
        [self checkCollision];
        enemy.center = CGPointMake(enemy.center.x+pos.x,enemy.center.y+pos.y);
       
        if (enemy.center.x >320 || enemy.center.x <0)
            pos.x = -pos.x;
        if (enemy.center.y > 480 || enemy.center.y <0)
            pos.y = -pos.y;
     
      [self checkCollision];
      enemy2.center = CGPointMake(enemy2.center.x+pos.x,enemy2.center.y+pos.y);
     
      if (enemy2.center.x >320 || enemy2.center.x <0)
          pos.x = -pos.x;
      if (enemy2.center.y > 480 || enemy2.center.y <0)
          pos.y = -pos.y;
     

       
       
  }
   
    -(void)checkCollision {
        if( CGRectIntersectsRect(player.frame,enemy.frame))
           
        {
           
            [randomMain invalidate];
            [startbutton setHidden:NO];
           
           
           
            CGRect frame = [player frame];
            frame.origin.x = 137.0f;
            frame.origin.y = 326.0;
            [player setFrame:frame];
           
           
            CGRect frame2 = [enemy frame];
            frame2.origin.x = 137.0f;
            frame2.origin.y = 20.0;
            [enemy setFrame:frame2];
           
        //    CGRect frame3 = [enemy2 frame];
          //  frame3.origin.x = 137.0f;
        //    frame3.origin.y = 20.0;
      //      [enemy2 setFrame:frame3];
        ///
         
           
           UIAlertView *alert_error = [[UIAlertView alloc] initWithTitle:@"You Lost!" message:@"You were hit! Try again!" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; [alert_error show];      [super viewDidUnload];
         
         
   
       
           
        }
       
       
        //enemy2
        if( CGRectIntersectsRect(player.frame,enemy2.frame))
           
        {
           
            [randomMain invalidate];
            [startbutton setHidden:NO];
           
           
           
            CGRect frame = [player frame];
            frame.origin.x = 137.0f;
            frame.origin.y = 326.0;
            [player setFrame:frame];
           
           
        //    CGRect frame2 = [enemy frame];
         //   frame2.origin.x = 137.0f;
        //    frame2.origin.y = 20.0;
       //     [enemy setFrame:frame2];
           
            CGRect frame3 = [enemy2 frame];
            frame3.origin.x = 137.0f;
            frame3.origin.y = 20.0;
            [enemy2 setFrame:frame3];
           
           
           
           
           
            UIAlertView *alert_error = [[UIAlertView alloc] initWithTitle:@"You Lost!" message:@"You were hit! Try again!" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; [alert_error show];      [super viewDidUnload];
           
        }
 
       
       
       
    }
    -(void)touchesMoved: (NSSet *) touches withEvent:(UIEvent *)event {
        UITouch *myTouch = [[event allTouches] anyObject];
        player.center = [myTouch locationInView:self.view];;
       
       
    }
   
   
   
   
   
-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
   
}

- (void)viewDidUnload
{
  [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
bidgadgetAsked:
Who is Participating?
 
Hamidreza VakilianConnect With a Mentor Senior iOS DeveloperCommented:
Ok, I can't debug your the code you provided unless you upload your whole project somewhere on internet (since it contains some variables which is defined in other files)
So please zip your project folder and upload it in some file sharing servers and provide the link so I can inspect the issue accurately.
(experts-exchange does not allow uploading zip files yet)
0
 
bidgadgetAuthor Commented:
I redid it and it works fine.  thanks for your offer to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.