我设置了一个分区,分区里面显示100行,如代码所示,我想只让第一行显示一个标题,于是利用indexPath.row进行判断是哪一行,但是运行程序后或出现一些错误,如图片,第一行确实是显示了”cell“,但是往下拉,发现第19行,第36行,第54行,还有几行也显示了这个”cell“,并且如果重新拉倒第一行,发现显示”cell“的行更乱了,请问是什么原因?不应该用indexPath.row进行判断吗?应该怎么判断?
-
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
if(indexPath.row==0)
{
cell.textLabel.text=@"cell";
}return cell;
}