crashes when using 'selectItem' to set default item
Closed this issue · 3 comments
plandem commented
[self.pickerMinutes selectItem:minutes animated:YES];
not matter what number i'm trying to set - crash in any case.
plandem commented
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
CATransition *transition = [CATransition animation];
[transition setType:kCATransitionFade];
[transition setDuration:0.15];
[self.label.layer addAnimation:transition forKey:nil];
UIFont *font = self.selected ? self.highlightedFont : self.font;
if ([self.label respondsToSelector:@selector(setAttributedText:)]) {
self.label.attributedText = [[NSAttributedString alloc] initWithString:self.label.attributedText.string
attributes:@{NSFontAttributeName: font}];
} else {
self.label.font = font;
}
}
self.label.attributedText - is nil, so 'initWithString:self.label.attributedText.string' will fail
plandem commented
what purpose of using attributedText in case if using font is not deprecated here.
cell.label.textColor = self.textColor;
cell.label.highlightedTextColor = self.highlightedTextColor;
cell.label.font = self.font;
cell.font = self.font;
cell.highlightedFont = self.highlightedFont;
if ([cell.label respondsToSelector:@selector(setAttributedText:)]) {
cell.label.attributedText = [[NSAttributedString alloc] initWithString:title
attributes:@{NSFontAttributeName: self.font}];
} else {
cell.label.text = title;
}
Actually you are using BOTH ways same time - NSString and NSAttributedString. What's the reason?
That:
cell.label.font = self.font;
cell.label.text = title;
and that:
cell.label.attributedText = [[NSAttributedString alloc] initWithString:title
attributes:@{NSFontAttributeName: self.font}];
is same in your case, because i don't see any other usage of attributedString(except of setting font and text). So is there any hidden purpose?