开发者

Create a new class and load some copies of it into the view

Ok, i made a small application with a small ball bouncing on the screen. That w开发者_JAVA百科as 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!


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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜