0
Matt,我讀了你的書中關於實現和接口的部分,我想知道這是否是將UIView子類放入接口的正確方法。如何將UIView子類放入界面?
@interface PDC : UIView
- (void)drawRect:(CGRect)rect;
- (id)initWithFrame:(CGRect)frame;
@end
Matt,我讀了你的書中關於實現和接口的部分,我想知道這是否是將UIView子類放入接口的正確方法。如何將UIView子類放入界面?
@interface PDC : UIView
- (void)drawRect:(CGRect)rect;
- (id)initWithFrame:(CGRect)frame;
@end
這些方法已經在基類UIView中定義了,所以你不需要在子類的接口中重新聲明它們。您可以在實現文件中覆蓋它們以添加您的子類的自定義行爲,並且您將能夠從其他類調用這些方法,因爲它們在UIView中已經公開。
如果它是UIView的子類,那麼遵守添加後綴'View'的命名約定也是不錯的。
@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
誰是「Matt」,他們寫了什麼書?堆棧溢出是一個普通的問題和答案網站,而不是特定的人的博客或個人網站。 – user1118321