This is my object class:
@class RKObjectMapping;
@interface MVCountryModel : NSObject
@property (strong, nonatomic) NSNumber *countryId;
@property (strong, nonatomic) NSString *countryName;
+ (RKObjectMapping *) responseMapping;
- (int) integerValue;
@end
First of all, i had to implement "integerValue" for displaying the picker in this way:
[MMPickerView showPickerViewInView:self.view
withObjects:_countries
withOptions:nil
objectToStringConverter:^NSString *(id object) {
return ((MVCountryModel *)object).countryName;
}
completion:^(id selectedObject) {
MVCountryModel *country = (MVCountryModel *)selectedObject;
[_labelCountry setText:country.countryName];
_selectedCountryId = country.countryId;
}];
But when a option where selected the app crash on my completion block because it only receive a NSString not an instance of my custom object class.
For make it work i had to change this method in this way:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (self.objectToStringConverter == nil) {
/* self.onDismissCompletion ([_pickerViewArray objectAtIndex:row]); */
self.onDismissCompletion (self.objectToStringConverter ([self selectedObject]));
} else{
/* self.onDismissCompletion (self.objectToStringConverter ([self selectedObject])); */
self.onDismissCompletion ([_pickerViewArray objectAtIndex:row]);
}
}
It looks so simple that i think i'm doing something wrong, but don't! Hope it helps.
This is my object class:
First of all, i had to implement "integerValue" for displaying the picker in this way:
But when a option where selected the app crash on my completion block because it only receive a NSString not an instance of my custom object class.
For make it work i had to change this method in this way:
It looks so simple that i think i'm doing something wrong, but don't! Hope it helps.