1
我有下面的代碼應該把圖像放在頂部的部分/單元格,然後在其他文字。我認爲問題是代碼試圖重新使用這個單元格,但是我無法弄清楚我應該改變什麼。你可以在這裏看到了問題的一個視頻:UITableView重繪沒有圖像和單元格被取代
http://screencast.com/t/OoQWMI5zCKVc
的代碼如下:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifierText = @"TextCell";
static NSString *CellIdentifierImage = @"ImageCell";
if (indexPath.section == 0)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierImage];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierImage] autorelease];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,180)];
imageView.tag = 1;
imageView.image = [UIImage imageNamed:@"prem.jpg"];
[cell addSubview:imageView];
[imageView release];
}
return cell;
}
else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierText];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifierImage] autorelease];
}
if(indexPath.section == 1)
cell.textLabel.text = [arryTableData objectAtIndex:indexPath.row];
else if(indexPath.section ==2)
cell.textLabel.text = [arryAddressInfo objectAtIndex:indexPath.row];
else if(indexPath.section == 3)
cell.textLabel.text = [arryTableActions objectAtIndex:indexPath.row];
else if(indexPath.section == 4)
cell.textLabel.text = @"REPLACE ME WITH ICONS";
return cell;
}
}
+1你打敗了我:) – Benjie
你甜心!非常感謝,看了很長時間 – TMB87
哈哈沒問題,有時你只需要一雙新鮮的眼睛。 –