自定义UITableViewCell(IB)仅在选定状态下显示

DAS*_*DAS 8 xcode uitableview ios

UITableViewCell在Interface Builder(Storyboard)中做了一个自定义,并通过它将它导入我的项目#import CustomTableViewCell.h.

一切正常,但单元格仅在选定状态下加载.

在此输入图像描述

我想通过init在每一行加载单元格.

PS滑块和文本字段连接正常工作.我还制作了所有的IB连接.

CustomTableViewCell.m

#import "CustomTableViewCell.h"

@implementation CustomTableViewCell

@synthesize sliderLabel, slider;

- (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

}

- (IBAction)getSliderValuesWithValue:(UISlider *)sender
{
sliderLabel.text = [NSString stringWithFormat:@"%i / 100", (int) roundf(sender.value)];
}

@end
Run Code Online (Sandbox Code Playgroud)

Further Code

- (CustomTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Kriterium";

CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

// Configure the cell...

cell.textLabel.text = [NSString stringWithFormat:@"%@", [listOfItems objectAtIndex:indexPath.row]];

return cell;
}
Run Code Online (Sandbox Code Playgroud)

PS如果我在上面的方法中以编程方式添加一些按钮等,它可以工作.但我想在IB中设计行.必须有一个解决方案.

DAS*_*DAS 17

好的...这里发生了奇怪的事情... ;-)问题是这一行:

 cell.textLabel.text = [NSString stringWithFormat:@"%@", [listOfItems objectAtIndex:indexPath.row]];
Run Code Online (Sandbox Code Playgroud)

离开它就可以了.我不得不在UILabel我的CustomCell中添加另一个我填充文本.

结论

填写标准UITableViewCell.textLabel.text似乎会覆盖PrototypeCells.

......过多的定制伤害.;-)

不管怎么说,还是要谢谢你!:)