[英]Using a subclass in storyboard's UIView
In my ViewController.h, I have the following. 在我的ViewController.h中,我有以下内容。
#import <UIKit/UIKit.h>
#import <TimesSquare/TimesSquare.h>
@interface PlusCalendarView : TSQCalendarView;
@end
@interface ViewController : UIViewController
@property (nonatomic, strong) NSCalendar *calendar;
//@property (strong, nonatomic) IBOutlet TSQCalendarView *myCalendarView;
@property (strong, nonatomic) IBOutlet PlusCalendarView *myCalendarView;
@end
I want to override some methods in TSQCalendarView, so I created a subclass called PlusCalendarView. 我想重写TSQCalendarView中的某些方法,所以我创建了一个称为PlusCalendarView的子类。 My storyboard looks like below: 我的故事板如下所示:
The one above is a UIView element and the other is a tableView. 上面的一个是UIView元素,另一个是tableView。 The UIView element has a custom class called "PlusCalendarView" and is connected to the PlusCalendarView outlet in ViewController.h UIView元素具有一个名为“ PlusCalendarView”的自定义类,并已连接到ViewController.h中的PlusCalendarView插座。
My question: This fails with an error Unknown class PlusCalendarView in Interface Builder file. 我的问题:这失败, 并在Interface Builder文件中出现错误Unknown class PlusCalendarView。 and I assume that's because storyboard doesn't know about my custom subview called PlusCalendarView. 我认为那是因为情节提要不了解我的自定义子视图PlusCalendarView。 What should I change to fix this problem? 我应该改变什么来解决这个问题?
You need to create the interface (.h) and implementation (.m) of your custom class. 您需要创建自定义类的接口(.h)和实现(.m)。 Use File new, tell it you want to create a Cocoa class named PlusCalendarView, and make it's base class TSQCalendarView. 使用File new,告诉它您要创建一个名为PlusCalendarView的可可类,并将其作为基类TSQCalendarView。 Add the files to your project and make sure the .m file is set to be included in your app target. 将文件添加到您的项目中,并确保将.m文件设置为包含在您的应用程序目标中。
That should do it. 那应该做。 Interface Builder knows how to find all the classes that are defined in the files in your project. Interface Builder知道如何查找项目文件中定义的所有类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.