我有一个UITableView有3个部分,每个返回numberOfRows 3个独立数组中的计数。在我的cellForRow中,我需要能够检测哪个单元是表中的第一个单元,哪个是最后一个。确定第一个和最后一个UITableViewCell
棘手的部分是,有时一个部分可以返回0的计数的行数,所以我有一个很难搞清楚了这一点。我想要做的是设置两个标志:isTopCell
和isBottomCell
。有任何想法吗?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section==0)
return [array1 count];
else if(section==1)
return [array2 count];
else return [array3 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(/*something, what I'm trying to figure out*/)
isTopCell=YES;
if(/*something, what I'm trying to figure out*/)
isBottomCell=YES;
}
编辑:让我澄清。这三个部分是统一的。我想确定整个顶部和底部的单元格。如果(indexPath.row == 0)将为3个部分返回true。我只需要1个赢家。
如果0节返回0的计数,该怎么办?这将打破 – Snowman 2012-03-30 13:55:31
@mohabitar谢谢,这应该是现在修复。 – dasblinkenlight 2012-03-30 14:01:30