Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with custom objects, objectToStringConverter and completion #18

Open
buguibu opened this issue Jun 26, 2014 · 1 comment
Open

Comments

@buguibu
Copy link

buguibu commented Jun 26, 2014

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.

@osorioabel
Copy link

I was having the same error , and use your solution and work perfect 👍 Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants