0

我在 UITableviewcell 上有一些标签我想更改 setter 中的标签字体但出于一些奇怪的原因

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

当我调试时,我看不到单元格内没有任何东西被分配。当我放下设置器时,一切正常,但使用我不想使用的系统字体。

有人可以帮我弄清楚为什么会这样吗?

单元格.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

单元格.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 倍为谁提供帮助..

4

1 回答 1

1

我相信你应该只设置标签的文本而不是创建并再次设置标签。例如

-(void) setLabelCountName:(UILabel *)labelCountName{
[self setLabel:labelCountName];

}

应该

-(void) setLabelCountName:(NSString *)labelCountName{
[self.labelCountName setText:labelCountName];

}

您也应该在 StoryBoard 设计器或 initWith... 方法中更改字体。

于 2013-03-12T13:56:46.337 回答