I made a custom UITableViewCell
in Interface Builder (Storyboard) and imported it to my project via #import CustomTableViewCell.h
.
Everything works fine, but the cell is only loaded in selected state.
I want the cell to be loaded in every row by init.
P.S. The slider and text field connections work fine. I also made all of the IB Connections.
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
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;
}
P.S. If I add some Buttons etc. programmatically in the above method it works. But I want to design the rows in IB. There has to be a solution.
Okay ... strange things happening here ... ;-) The problem was this line:
cell.textLabel.text = [NSString stringWithFormat:@"%@", [listOfItems objectAtIndex:indexPath.row]];
Leaving it out did the trick. I had to add another UILabel
to my CustomCell which I fill with text.
CONCLUSION
Filling the standard UITableViewCell.textLabel.text
seems to overwrite the PrototypeCells.
... too much customization hurts. ;-)
Thanks anyway! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With