[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 786
  • Last Modified:

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
0
bidgadget
Asked:
bidgadget
1 Solution
 
Hamidreza VakilianSenior 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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now