2
用自定义单元格加载tableview后,所有看起来很好,向下滚动都很好。 当我向上滚动上面的单元格显示空白。它们实际上功能完备,因为它们仍然可以被选中,然后进入细节页面。 代码cellForRowAtIndexPath为返回的行执行,并返回单元格,正如我所期望的正确的细节。它只是不显示。 任何想法/帮助,将不胜感激。当再次滚动tableview时,单元格显示为空白?
下面的代码是我一直在使用的。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id oneObject in nib) {
if ([oneObject isKindOfClass:[CustomCell class]]) {
cell = (CustomCell *)oneObject;
}
}
}
// Configure the cell.
Book *aBook = [appDelegate.sortedArray objectAtIndex:indexPath.row];
//name
NSString *trimmedString = [aBook.Name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
cell.nameLabel.text = trimmedString;
//catagory
NSString *trimmedExperience = [aBook.PrimaryExperience stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([trimmedExperience isEqualToString:@"1"]) {
cell.catagoryLabel.text = @"None";
}
else if([trimmedExperience isEqualToString:@"2"]){
cell.catagoryLabel.text = @"Limited";
}
else if ([trimmedExperience isEqualToString:@"4"]) {
cell.catagoryLabel.text = @"Full";
}
else {
cell.catagoryLabel.text = @"";
}
cell.distanceLabel.text = [NSString stringWithFormat:@"%1.1f",aBook.distance];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
您究竟如何渲染细胞?您是使用Interface Builder还是从头开始? – medopal
单元格从界面生成器中呈现,文本在cellForRowAtIndexPath中设置 - 奇怪的是,它们工作得很漂亮,直到他们滚出顶部。 – Davida
你可以显示cellForRowAtIndexPath方法吗? – jrturton