UITableView中有2种不同类型的自定义UITableViewCell [英] 2 different types of custom UITableViewCells in UITableView
问题描述
在我的UITableView中我想设置rss feed的第一个新闻自定义tableViewCell(类型A让我们说)和另一个新闻第二,第三等等。另一个自定义tableViewCell(trype B)的问题是,为第一个新闻创建的自定义tableViewCell(trype A)被重用,但奇怪的是第一次使用customViewCell(类型A)和第二次出现相同类型的customViewCell之间的行数不相等。
in my UITableView i want to set for the first news of an rss feed a custom tableViewCell(Type A lets say) and for the other news second, third etc.. another custom tableViewCell(trype B) the problem is that the custom tableViewCell(trype A) created for the first news is reused, but curiously the number of rows between the first use of the customViewCell(type A) and the second appearance of the same type of customViewCell is not equal..
我的cellForRowAtIndexPath它看起来像这样。
my cellForRowAtIndexPath it looks like this.
- (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自定义单元格只出现在第一个新闻(不被重用)?谢谢
the the two types of cells have different heights which is set correctly. could someone point me in the right direction on how to make the type A custom cell to appear only for the first news(not being reused)? thank you
推荐答案
您应该为两种样式的单元格创建不同的单元格标识符:
You should create a different cell identifier for the two styles of cell:
- (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 *CellIdentifier1 = @"Cell1";
static NSString *CellIdentifier2 = @"Cell2";
if(feedIndex == 0) {
MainArticleTableViewCell *cell = (MainArticleTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
cell = [[[MainArticleTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];
[[[cell subviews] objectAtIndex:0] setTag:111];
}
cell.feed = item;
return cell;
}
else {
NewsTableViewCell *cell = (NewsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil) {
cell = [[[NewsTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier2 orientation:currentOrientation] autorelease];
[[[cell subviews] objectAtIndex:0] setTag:111];
}
cell.feed = item;
return cell;
}
return nil;
}
这篇关于UITableView中有2种不同类型的自定义UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!