ios - UITableView 中不可见的标签文本

标签 ios objective-c uitableview cell

我已经为最基本的创建了一个自定义表格。我制作了一个标签栏 Controller 。

FoglalasTableViewCell.h

@interface FoglalasTableViewCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *datumLabelFoglalas;
@property (weak, nonatomic) IBOutlet UILabel *adminNevekLabelFoglalas;

@end

FoglalasTableViewCell.m

#import "FoglalasTableViewCell.h"

@implementation FoglalasTableViewCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdent = @"foglalas";
    
    FoglalasTableViewCell *Cellw = [tableView dequeueReusableCellWithIdentifier:CellIdent];
    
    if (!Cellw) {
        Cellw = [[FoglalasTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdent];
        // Cellw = [[FoglalasTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdent];
    }
    
    if (Cellw.backgroundView == nil) {
    
        if ([foglaltArr[indexPath.row] isEqual: @0]) {
            [Cellw setBackgroundColor:[UIColor greenColor]];
        } else if ([foglaltArr[indexPath.row] isEqual: @1]) {
            [Cellw setBackgroundColor:[UIColor redColor]];
        }
    }
    
    NSLog(@"%d. foglaltArr : %@",indexPath.row, [foglaltArr objectAtIndex:indexPath.row]);

    NSLog(@"%d orakArr %@",indexPath.row,orakArr[indexPath.row]);

    Cellw.datumLabelFoglalas.text = [foglaltArr objectAtIndex:indexPath.row];
    Cellw.adminNevekLabelFoglalas.text = @"blah..";

    return Cellw;
    
}

我插入了数据源。 它改变了单元格的背景颜色。 但是标签没有获取数据源。 我不明白为什么要得到背景的来源,为什么不得到标签!?我不知道如何解决。 请帮助我。

![背景源可见][1]

最佳答案

我会将属性声明为 nonatomic, strong。我也会合成它们。

同时检查您将元素与您的 View 相关联。

最后才调用nib

FoglalasTableViewCell *cell = (FoglalasTableViewCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FoglalasTableViewCell" owner:self options:nil];
    cell = (FoglalasTableViewCell *)[nib objectAtIndex:0];
}

关于ios - UITableView 中不可见的标签文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28759410/

相关文章:

ios - '-[__NSCFNumber 行] : unrecognized selector sent to instance 0xb416910'

objective-c - UITableView 层上的内部阴影?

android - RubyMotion - 联合 iOS/Android 开发

ios - 为什么我的 Xamarin.Forms 应用程序中的 acr.UserDialogs.Toast 消息在设备上被截断?

ios - 如何在下面给出的 Hidekeyboard 函数中包含多个 UITextField?

iOS 动画 : CADisplayLink vs CAShapeLayer

ios - 如何使用 AttributedString 正确设置 UILabel 的行高?

ios - UITextField仅允许输入英文字母

ios - 将图像从 UIimageView 保存到 Core Data

ios - UITableview - 为单元格设置属性与重复使用的单元格混淆