Zrobiłem niestandardowy UITableViewCell
w Konstruktorze interfejsu (Storyboard) i zaimportowałem go do mojego projektu przez #import CustomTableViewCell.h
.Niestandardowy UITableViewCell (IB) pokazuje tylko w wybranym stanie
Wszystko działa poprawnie, ale komórka jest załadowana tylko w wybranym stanie.
Chcę komórka być załadowany w każdym rzędzie przez init.
P.S. Połączenia między suwakiem i polem tekstowym działają dobrze. Zrobiłem również wszystkie połączenia 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
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;
}
PS: Jeśli dodaję niektóre przyciski itp. Programowo w powyższej metodzie, to działa. Ale chcę zaprojektować rzędy w IB. Musi być jakieś rozwiązanie.
Czy możesz umieścić kod dla metody cellForRowAtIndexPath używanej przy wypełnianiu UITableView wierszami? – reddersky
Zaktualizowałem moją odpowiedź. – DAS
Czy zaprojektowałeś tę komórkę w oddzielnym stalówce lub jako prototyp w widoku tabeli w scenorysie? – jrturton