我想创建一个带有自定义分隔符的tableview。我制作了一个自定义Cell来保存内容,另一个只包含带有分隔符的UIImageView。 问题在于如何访问内容。 我不能使用indexPath.row错误创建自定义表格分隔符
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier: @"CustomCell"];
if(cell == nil)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
}
SeparatorCell *cellSeparator = (SeparatorCell *) [tableView dequeueReusableCellWithIdentifier: @"SeparatorCell"];
if(cellSeparator == nil)
{
cellSeparator = [[[NSBundle mainBundle] loadNibNamed:@"SeparatorCell" owner:self options:nil] objectAtIndex:0];
}
if(indexPath.row % 2)
{
UIFont * myCustomFont = [UIFont fontWithName:@"Arial Black" size:16];
[cell.titulo setFont:myCustomFont];
cell.titulo.textColor = [UIColor colorWithRed:103/255.0f green:169/255.0f blue:0/255.0f alpha:1];
cell.titulo.text = [Title objectAtIndex:myRow];
cell.subtitle.text = [Subtitle objectAtIndex:myRow];
cell.tag = myRow;
myRow++;
}
else [cellSeparator.imagem setImage:[UIImage imageNamed:@"CustomSeparator.png"]];
if(indexPath.row % 2) return cell;
else return cellSeparator;
}
myRow
是一个全球性的NSInteger的。
我已经尝试过
if(myRow == Title.count) myRow=0;
else myRow++;
当你使用它时会发生什么? – Dustin 2012-07-12 14:22:40
我在tableview中往下走,一行消失,当我再次看到那一行时,Xcode给了我一个错误,试图访问数组中不存在的对象,我相信变量> myRow 没有重置。 – darkman 2012-07-12 14:36:00
而不是使用变量'myRow',为什么不使用'indexPath.row%2'? – Dustin 2012-07-12 14:37:59