【发布时间】:2010-11-27 04:50:17
【问题描述】:
在我的 UITableView 中,我想为 rss 提要的第一个新闻设置一个自定义 tableViewCell(可以说是 A 类),另一个新闻是第二个、第三个等。另一个自定义 tableViewCell(trype B)问题是为第一个新闻创建的自定义 tableViewCell(trype A) 被重复使用,但奇怪的是第一次使用 customViewCell(type A) 和第二次出现相同类型的 customViewCell 之间的行数不相等..
我的 cellForRowAtIndexPath 看起来像这样。
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
int feedIndex = [indexPath indexAtPosition:[indexPath length] - 1];
Feed *item = [[[[self selectedButton] category] feedsList] objectAtIndex:feedIndex + 1];
static NSString *CellIdentifier = @"Cell";
if(feedIndex == 0){
MainArticleTableViewCell *cell = (MainArticleTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[MainArticleTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
[[[cell subviews] objectAtIndex:0] setTag:111];
}
cell.feed = item;
return cell;
}
else{
NewsTableViewCell *cell = (NewsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[NewsTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier orientation:currentOrientation] autorelease];
[[[cell subviews] objectAtIndex:0] setTag:111];
}
cell.feed = item;
return cell;
}
return nil;
}
这两种类型的单元格具有不同的高度,这是正确设置的。有人可以为我指出正确的方向,如何使 A 型自定义单元格仅出现在第一个新闻中(不被重用)?谢谢
【问题讨论】:
-
有关此问题的 Swift 版本,请参阅 here
标签: iphone uitableview