我有一个很难理解下面的代码块中的cellForRowAtIndexPath:定制电池的再利用5.1
NSString *uniqueIdentifier = @"SliderCellWithComments";
SliderCellWithComment *cell = nil;
cell = (SliderCellWithComment*) [tableView dequeueReusableCellWithIdentifier:uniqueIdentifier];
if(!cell)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SliderCellWithComment" owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[SliderCellWithComment class]])
{
cell = (SliderCellWithComment*)currentObject;
cell.delegationListener = self; //important!!
cell.indexPath = [indexPath copy]; //important!!
break;
}
}
[cell setNameLabelText:@"Days to display:"];
.
.
.
我从StackOverflow上得到这个代码,直到我试图运行它,它工作得很好iOS 5.1,它崩溃时发生错误:'NSInternalInconsistencyException',原因:'NIB数据无效'。
但我不明白的代码是,它似乎并没有真正重用任何东西。
例如: 为什么此代码将值分配给“单元格”两次?
细胞=(SliderCellWithComment *)[的tableView dequeueReusableCellWithIdentifier:唯一标识符];
cell =(SliderCellWithComment *)currentObject;
如果2个执行,根据我来说,没有什么是被重新使用,因为小区被分配从新笔尖的值。
我真的不明白使用数组的任一,为什么下面的代码呈现空白单元格:
static NSString *CellIdentifier = @"SliderCellWithComments";
SliderCellWithComment *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[SliderCellWithComment alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
[cell setNameLabelText:@"Days to display:"];
cell.delegationListener = self; //important!!
cell.indexPath = [indexPath copy]; //important!!
.
.
.
我解决了这个问题,通过将我的单元格中的标签从归为普通的方式更改。但是,我仍然需要了解上面的代码,请查看我关于数组及其在单元重用中的作用的问题。 – 2013-05-10 08:59:16