Özel bir UITableViewCell ile ilgili bazı sorunlar ve hikaye tahtalarını kullanarak işleri nasıl yöneteceğim. Stil kodunu initWithCoder:
içine koyduğumda işe yaramıyor ama eğer tableView: cellForRowAtIndexPath:
içine koyarsam işe yarıyor. Hikaye panosunda, UITableViewCell özel sınıfım ayarlı sınıf özniteliğine sahip bir prototip hücrem var. Şimdi initWithCoder:
'daki kod aranıyor. Ben kodu debug ve dequeue...
ilk denir buldukÖzelleştirilmiş UITableViewCell initWithCoder: çalışma değil
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"NearbyLandmarksCell";
SimoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//sets the text of the labels
id<SimoListItem> item = (id<SimoListItem>) [self.places objectAtIndex:[indexPath row]];
cell.mainLabel.text = [item mainString];
cell.subLabel.text = [item subString];
//move the labels so that they are centered horizontally
float mainXPos = (CGRectGetWidth(cell.contentView.frame)/2 - CGRectGetWidth(cell.mainLabel.frame)/2);
float subXPos = (CGRectGetWidth(cell.contentView.frame)/2 - CGRectGetWidth(cell.subLabel.frame)/2);
CGRect mainFrame = cell.mainLabel.frame;
mainFrame.origin.x = mainXPos;
cell.mainLabel.frame = mainFrame;
CGRect subFrame = cell.subLabel.frame;
subFrame.origin.x = subXPos;
cell.subLabel.frame = subFrame;
return cell;
}
SimoTableViewCell.m
@implementation SimoTableViewCell
@synthesize mainLabel, subLabel;
-(id) initWithCoder:(NSCoder *)aDecoder {
if (!(self = [super initWithCoder:aDecoder])) return nil;
[self styleCellBackground];
//style the labels
[self.mainLabel styleMainLabel];
[self.subLabel styleSubLabel];
return self;
}
@end
TableViewController.m, o zaman o initWithCoder:
ve gider Görüntü denetleyici koduna geri dönün. Garip olan şey, bellekteki hücrenin adresinin return self;
arasında ve denetleyiciye geri döndüğünde değişmesidir. Ve eğer stil kodunu dequeue...
'dan sonra görüntü denetleyicisine geri döndürürsem, her şey iyi çalışıyor. Sadece hücreleri yeniden kullanırken gereksiz bir stil yapmak istemiyorum. initWithCoder:
sonra
Alkış