This question relates to this SO question (please see accepted answer). I'm adding a UIPickerView to a view which has not added the UIPickerViewDelegate or UIPickerViewDataSource protocols in its interface. However, all the required methods for the UIPickerView object has been properly implemented, and the program runs fine with these delegates:
pv.delegate = self;
pv.dataSource = self;
Since the protocols are not added in the class interface, Xcode throws these two warnings accordingly:
Assigning to 'id<UIPickerViewDelegate>' from incompatible type
Assigning to 'id<UIPickerViewDataSource>' from incompatible type
This code seems to add the required protocols, and the warnings stop as soon as the picker view delegate and datasource properties are assigned the newly created delegateClass.
UIPickerView *pv = [[UIPickerView alloc] initWithFrame:CGRectMake(x, y, width, height)];
Class<UIPickerViewDelegate, UIPickerViewDataSource> delegatedClass = (Class<UIPickerViewDelegate, UIPickerViewDataSource>)[self class];
pv.delegate = delegatedClass;
pv.dataSource = delegatedClass;
However, even with no errors, the program crashes.
Is the implementation or assignment wrong, perhaps?
UPDATE: screenshot of the error