简体   繁体   English

在情节提要的UIView中使用子类

[英]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.

相关问题 iOS Storyboard,带有UIView的子类 - iOS Storyboard with Subclass of UIView 如何使用带有Storyboard的Autolayout获取UIView子类的框架? - How can I get the frame of a UIView subclass using Autolayout with Storyboard? 将在情节提要中定义的UIView“铸造”到子类 - 'Casting' a UIView defined in Storyboard to a subclass 将 UIViewController 子类的子类与 UIView 子类的子类一起使用 - Using a subclass of UIViewController subclass with subclass of UIView subclass UIView的子类未绘制在情节提要中工作的子视图 - Subclass of UIView not drawing subviews working in storyboard 如何将情节提要UIView设置为视图的子类? - How to set storyboard UIView to subclass of view? iOS:在故事板中将子类从UIView更改为UIScrollView - iOS: Changing subclass from UIView to UIScrollView in a storyboard 无法将 IBOutlet 从 storyboard 连接到 UIView 子类 - Unable to connect IBOutlet from storyboard to UIView subclass 使用AutoLayout(故事板)自动调整UIView的高度到它的子视图 - Automatically Adjust UIView's Height to It's Subview using AutoLayout (Storyboard) 在情节提要板上使用UIButton子类会使按钮的边框消失 - Using a UIButton subclass on the storyboard makes the button's border vanish
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM