PK8*_*K86 4 uitableview unrecognized-selector ios7
@interface PromotionsListViewController : UITableViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PromotionCell";
PromotionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[PromotionCell alloc] init];
}
// Configure the cell...
Promotion *promotion = [self.promotionList objectAtIndex:indexPath.row];
[cell.imgView setImageWithURL:[NSURL URLWithString:promotion.imageURL] placeholderImage:[UIImage imageNamed:@""]];
cell.lblTitle.text = promotion.promotionTitle;
return cell;
}
@interface PromotionCell : UITableViewCell
@property(nonatomic, strong) UIImageView *imgView;
@property(nonatomic, strong) UILabel *lblTitle;
@end
- (void)layoutSubviews {
if (self.lblTitle.text) {
CGSize maxsize = CGSizeMake(300, CGFLOAT_MAX);
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
CGRect calculateRect = [_lblTitle.text boundingRectWithSize:maxsize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:_lblTitle.font, NSParagraphStyleAttributeName:paragraphStyle.copy} context:nil];
_lblTitle.frame = CGRectMake(_lblTitle.frame.origin.x, 300 - calculateRect.size.height - 5, _lblTitle.frame.size.width, calculateRect.size.height);
} else {
_lblTitle.frame = CGRectZero;
}
}
- (UILabel *)lblTitle {
if (!_lblTitle) {
_lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 250, 300, 50)];
_lblTitle.font = [UIFont boldSystemFontOfSize:22.0f];
_lblTitle.numberOfLines = 0;
_lblTitle.lineBreakMode = NSLineBreakByWordWrapping;
[self.contentView addSubview:_lblTitle];
}
return _lblTitle;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我,我做错了什么?我希望我的问题很清楚..
我也有这个问题.原来有两种类似的方法boundingRectWithSize:.一个为NSString一个为一个NSAttributedString.
适用于iOS 6及更高版本的NSAttributedString的以下内容:
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context
另一个NSString方法(您当前正在使用)仅适用于iOS 7:
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context
因此,只需在Attributed String上调用boundingRectWithSize:方法而不需要额外的Attributes:字段,它就可以在iOS 6上正常工作.
| 归档时间: |
|
| 查看次数: |
5067 次 |
| 最近记录: |