0

In my ViewController.h, I have the following.

#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. My storyboard looks like below:

enter image description here

The one above is a UIView element and the other is a tableView. The UIView element has a custom class called "PlusCalendarView" and is connected to the PlusCalendarView outlet in ViewController.h

My question: This fails with an error Unknown class PlusCalendarView in Interface Builder file. and I assume that's because storyboard doesn't know about my custom subview called PlusCalendarView. What should I change to fix this problem?

Maximus S
  • 10,759
  • 19
  • 75
  • 154

1 Answers1

0

You need to create the interface (.h) and implementation (.m) of your custom class. Use File new, tell it you want to create a Cocoa class named PlusCalendarView, and make it's base class TSQCalendarView. Add the files to your project and make sure the .m file is set to be included in your app target.

That should do it. Interface Builder knows how to find all the classes that are defined in the files in your project.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Can you tell me how I can call a method inside ViewController from PlusCalendarView? I want to call performSegueWithIdentifier and I believe the right place to do that is ViewController. – Maximus S Oct 26 '14 at 22:54
  • You wrote "Can you tell me how I can call a method inside ViewController from PlusCalendarView?" I'm not sure what you're asking. You want to know how to call back from your PlusCalendarView into the owning view controller? Is PlusCalendarView a UIView or a UIViewController? If it's a view, then there are no segues involved. The view controller simply contains a PlusCalendarView object. – Duncan C Oct 26 '14 at 23:11
  • 1
    Assuming I understand what you want to do: Define a protocol PlusCalendarViewParentVCProtocol. Have your ViewController conform to that protocol. Add a ParentVC property to your PlusCalendarView. In your ViewController's viewDidLoad, set the PlusCalendarView's parentVC property to point to self (the ViewController.) Then, any time you want to call a method in your parent view controller, send the messages to the parentVC object. – Duncan C Oct 26 '14 at 23:14
  • Thank you. I elaborated what I want to do in this [post](http://stackoverflow.com/questions/26578837/how-to-show-a-view-programmatically). I think using a protocol might be the right way to do it but am still not sure. – Maximus S Oct 26 '14 at 23:27