Leahcim
Leahcim

Reputation: 42009

setting an imported class to be delegate

I created a subclass of UIPickerView

@interface ClockPicker : UIPickerView
@property (strong, nonatomic) NSArray *manyNumbers;

@end

and imported it into my viewController and instantiate it like this

#import "clockPicker.h"
@interface sfViewController ()

@property (strong, nonatomic) ClockPicker *clockPicker;


@end

@implementation sfViewController

-(ClockPicker *)clockPIcker
{
    if (!_clockPicker) _clockPicker = [[ClockPicker alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
    return _clockPicker;
}

UIPickerView has several protocol methods that have to be implemented so I have to say what the delegate and the datasource are. In viewDidLoad of the viewController, I can do this to make the viewController the delegate and the datasource

clockPickerView.delegate = self;
clockPickerView.dataSource = self;

However, I want to set the imported UIPickerView class to be the delegate and the datasource. If i do this

clockPickerView.delegate = ClockPicker;
clockPickerView.dataSource = ClockPicker;

I get an error unexpected interface name ClockPicker expected expression.

How would I set the class in the imported file to be the delegate and datasource so that I can set up the required methods in that file rather than in the viewController?

Upvotes: 1

Views: 71

Answers (1)

Wayne
Wayne

Reputation: 60424

You need to assign an instance of the ClockPicker to delegate and dataSource (not the class itself).

The error you're getting:

unexpected interface name ClockPicker expected expression

...is saying that the compiler expected the righthand side of an assignment to be an expression, but you gave it the name of an interface, which is an error.

Upvotes: 2

Related Questions