Reputation: 426
How to change color of the first and last row in the group UITableView?
I would like to sharing my solution with you but I don't know how, so I create this question. sorry for that.
Upvotes: 0
Views: 450
Reputation: 40211
In your UITableViewDataSource
method tableView:cellForRowAtIndexPath:
do something like this, after your cell has been set up:
if (indexPath.row == 0 ||
indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {
cell.backgroundColor = [UIColor redColor]; // or anything you want.
}
Upvotes: 2
Reputation: 426
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
[self configureCell:cell atIndexPath:indexPath];
for (int x = 0; x < [[self.fetchedResultsController sections] count]; x++) {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:x];
int d = [sectionInfo numberOfObjects];
if(indexPath.section == x){
if (indexPath.row == 0 || indexPath.row == d-1) {
cell.backgroundColor = [UIColor blackColor];
}else{
cell.backgroundColor = [UIColor whiteColor];
}
}
}
return cell;
}
Upvotes: 0