Ho creato un oggetto personalizzato UITableViewCell
in Interface Builder (Storyboard) e l'ho importato nel mio progetto tramite #import CustomTableViewCell.h
.Personalizzato UITableViewCell (IB) mostra solo nello stato selezionato
Tutto funziona correttamente, ma la cella viene caricata solo nello stato selezionato.
voglio la cella da caricare in ogni riga da init.
P.S. Le connessioni del campo di scorrimento e di testo funzionano correttamente. Ho anche realizzato tutte le connessioni 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;
}
P.S. Se aggiungo alcuni pulsanti ecc. Programmaticamente nel metodo sopra, funziona. Ma voglio progettare le righe in IB. Ci deve essere una soluzione.
È possibile inserire il codice per il metodo cellForRowAtIndexPath utilizzato quando si popola UITableView con le righe? – reddersky
Ho aggiornato la mia risposta. – DAS
Hai progettato questa cella in un pennino separato o come prototipo nella visualizzazione tabella nello storyboard? – jrturton