我在UITableviewcell上有一些标签我想更改setter中的标签字体,但是出于一些奇怪的原因
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
当我调试时,我看到单元格内部没有任何内容被分配.. 当我删除setter时,一切正常,但系统字体我不想使用。
有人可以帮我弄清楚它为什么会发生?
Cell.h文件
#import <UIKit/UIKit.h>
@interface CheckoutCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *labelQuantity;
@property (weak, nonatomic) IBOutlet UILabel *labelMainDescription;
@property (weak, nonatomic) IBOutlet UILabel *labelCountName;
@property (weak, nonatomic) IBOutlet UILabel *labelInchSize;
@property (weak, nonatomic) IBOutlet UILabel *labelMMsize;
@property (weak, nonatomic) IBOutlet UILabel *labelStaticTotal;
@property (weak, nonatomic) IBOutlet UILabel *labelTotalPrice;
@property (weak, nonatomic) IBOutlet UILabel *label_ItemPrice;
@property (weak, nonatomic) IBOutlet UIButton *btnBuyAnotherProduct;
@property (weak, nonatomic) IBOutlet UIButton *btnAddAnotherSet;
@end
cell.m文件
#import "CheckoutCell.h"
@implementation CheckoutCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void) setLabelCountName:(UILabel *)labelCountName
{
[self setLabel:labelCountName];
}
-(void) setLabelMMsize:(UILabel *)labelMMsize
{
[self setLabel:labelMMsize];
}
-(void) setLabel_ItemPrice:(UILabel *)label_ItemPrice
{
[self setLabel:label_ItemPrice];
}
-(void) setLabelInchSize:(UILabel *)labelInchSize
{
[self setLabel:labelInchSize];
}
-(void) setLabelMainDescription:(UILabel *)labelMainDescription
{
[labelMainDescription setFont:[UIFont fontWithName:@"MuseoSans-500" size:14]];
}
-(void) setLabelQuantity:(UILabel *)labelQuantity
{
[labelQuantity setFont:[UIFont fontWithName:@"MuseoSans-500" size:18]];
}
-(void) setLabelTotalPrice:(UILabel *)labelTotalPrice
{
[labelTotalPrice setFont:[UIFont fontWithName:@"MuseoSans-500" size:14]];
}
-(void) setLabelStaticTotal:(UILabel *)labelStaticTotal
{
[labelStaticTotal setFont:[UIFont fontWithName:@"MuseoSans-500" size:14]];
}
//BTN setters
-(void) setBtnAddAnotherSet:(UIButton *)btnAddAnotherSet
{
[btnAddAnotherSet.titleLabel setFont:[UIFont fontWithName:@"MuseoSans-500" size:12]];
btnAddAnotherSet.titleLabel.textAlignment = UIBaselineAdjustmentAlignCenters;
}
-(void) setBtnBuyAnotherProduct:(UIButton *)btnBuyAnotherProduct
{
[btnBuyAnotherProduct.titleLabel setFont:[UIFont fontWithName:@"MuseoSans-500" size:12]];
btnBuyAnotherProduct.titleLabel.textAlignment = UIBaselineAdjustmentAlignCenters;
}
//generic setter
-(void) setLabel:(UILabel *)label
{
[label setFont:[UIFont fontWithName:@"MuseoSans-300" size:10]];
}
@end
提前10倍为谁提供帮助..
答案 0 :(得分:1)
我相信您应该只设置标签的文字而不是创建并再次设置标签。例如
-(void) setLabelCountName:(UILabel *)labelCountName{
[self setLabel:labelCountName];
}
应该是
-(void) setLabelCountName:(NSString *)labelCountName{
[self.labelCountName setText:labelCountName];
}
你也应该改变StoryBoard设计器中的Font或initWith ...方法。