user3349248
user3349248

Reputation: 1

How do I put the UIView subclass into the interface?

Matt, I read the part of your book about implementation and interface and I was wondering if this was the correct way to put the UIView subclass into the interface.

@interface PDC : UIView
- (void)drawRect:(CGRect)rect;
- (id)initWithFrame:(CGRect)frame;
@end

Upvotes: 0

Views: 51

Answers (1)

subjective_c
subjective_c

Reputation: 302

Those methods are already defined in the base class, UIView, so you don't need to re-declare them in the subclass's interface. You can override them in the implementation file to add your subclass's customized behavior, and you will be able to call those methods from other classes because they are already public in UIView.

It is also good to follow the naming convention of adding the suffix 'View' if it is a subclass of a UIView.

@interface PDCView : UIView
@end


@implementation PDCView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
         // Your custom initialization here
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    // Your logic here
}

@end

Upvotes: 1

Related Questions