Skip to content

Problem with custom objects, objectToStringConverter and completion #18

Description

@buguibu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions