im working on this project where i am trying to get a 4-4 red square to bounce around the screen but every time i run this code it gives a thread error that says Thread 1:signal SIGABRT i am fairly new to objective-c can any one help me with what I am trying to do? here is my code
#import <UIKit/UIKit.h>
@class home;
@interface ViewController : UIViewController{
ViewController* home;
CGFloat rhx;
CGFloat rhy;
CGFloat red_direction_x;
CGFloat red_direction_y;
}
@property CGFloat rhx;
@property CGFloat rhy;
@property CGFloat red_direction_x;
@property CGFloat red_direction_y;
@property ViewController* home;
@end
#import "ViewController.h"
@implementation ViewController
@synthesize rhx,rhy, red_direction_x, red_direction_y, home;
-(void)event:(NSTimer*)timername{
UIView* redhead = [[UIView alloc]initWithFrame:CGRectMake(rhx, rhy, 4, 4)];
redhead.backgroundColor = [UIColor redColor];
[self.view addSubview:redhead];
if (rhx >= self.view.bounds.size.width) {
red_direction_x = -4;
} else if (rhx <= 0) {
red_direction_x = 4;
}
if (rhy <= 0) {
red_direction_y = 4;
} else if (rhy >= self.view.bounds.size.height) {
red_direction_y = -4;
}
rhx += red_direction_x;
rhy += red_direction_y;
}
- (void)viewDidLoad {
self.home = [[ViewController alloc] init];
red_direction_x = 4;
red_direction_y = -4;
rhx = 4;
rhy = 4;
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(event)
userInfo:nil
repeats:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end