tags:

views:

42

answers:

3

Ok, i made a small application with a small ball bouncing on the screen. That was esay. Now i'd like to have more than one ball... so i think the best way is to create a new class : the ball.

How can i do it?

Thanks!

+1  A: 

encapsulate the information about the ball from your first app into variables, and create methods for any actions you think the ball performs. This sounds a lot like an object-oriented design problem..perhaps you should take a look at an Object Oriented Programming guide, such as this one OOP Guide

but if you are asking how to create a custom object class.. put this in your Ball.h:

#import <Foundation/Foundation.h>

@interface Ball : NSObject {

    IBOutlet UIButton *button; //sample instance variable
}

@property  (retain) UIButton *button;
@end

then in your .m file:

#import "Ball.h"

@implementation Ball
@synthesize button;

-(void)dealloc
{
[button release];
[super dealloc];
}

@end
Jesse Naugher
Hi Jesse, thank you very much for your answer.I'll try to be more precise about my problem:This "ball" should be associated to an image of a ball. I made this in Interface Builder, doing like this:* Loaded a png file in Xcode* Created an IBOutlet UIImageView named "ball"* In Interface Builder, I have added a UIImageView on the main view and linked it to "ball".* Added some methods*Everything working fine.But now, with the class, how can I do the same things?I'd like to pick my png image and associate it to every instance of Ball, and have it on my view.Thanks!
Abramodj
A: 

Hi Jesse, thank you very much for your answer. I'll try to be more precise about my problem: This "ball" should be associated to an image of a ball. I made this in Interface Builder, doing like this:

  • Loaded a png file in Xcode * Created an IBOutlet UIImageView named "ball"
  • In Interface Builder, I have added a UIImageView on the main view and linked it to "ball".
  • Added some methods
  • Everything working fine.

But now, with the class, how can I do the same things? I'd like to pick my png image and associate it to every instance of Ball, and have it on my view. Thanks!

Abramodj
A: 

Ok i made it! Thanks

Abramodj