I have a UITableView with 3 sections, each returning for numberOfRows the count in 3 separate arrays. In my cellForRow, I need to be able to detect which cell is the first cell in the table and which is the last.
The tricky part is that sometimes a section can return a count of 0 for number of rows, so I’m having a hard time figuring this out. All I’m trying to do is set two flags: isTopCell and isBottomCell. Any ideas?
- (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;
}
Edit: Let me clarify. The 3 sections are unified. I want to determine the overall top and bottom cell. if(indexPath.row==0) will return true for 3 sections. I need only 1 winner.
Try this: