Skip to content

Commit

Permalink
add fallback method since attributedTitleForRow is not availiable in …
Browse files Browse the repository at this point in the history
…iOS5.
  • Loading branch information
ainopara committed Jul 21, 2015
1 parent 8a9b599 commit 3b11e7f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Pickers/ActionSheetStringPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSIn
return self.data.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
id obj = (self.data)[(NSUInteger) row];

// return the object if it is already a NSString,
// otherwise, return the description, just like the toString() method in Java
// else, return nil to prevent exception

if ([obj isKindOfClass:[NSString class]])
return obj;

if ([obj respondsToSelector:@selector(description)])
return [obj performSelector:@selector(description)];

return nil;
}

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
id obj = (self.data)[(NSUInteger) row];

Expand Down

0 comments on commit 3b11e7f

Please sign in to comment.