Reputation: 1958
I want to add a cell in the bottom that shows only if the app is loading more results when the user scrolls to the bottom of a tableview. I already did that. The problem is that it's a cell. So when I scroll down even further, the separator shows that it's just another cell in the table. I want to hide that. I have to change that cell's separator color, how do I do that to a particular cell? Also, Where/when do i do that?
I realize that if I change that cell's color (let's say it's #5), when I get the results and load them in, won't that also result in cell #5 still having an invisible separator? So how do I set it back to the default color? More particularly how do I get the default color for a tableviewcellseparator programmatically?
Thanks
Upvotes: 1
Views: 822
Reputation: 2865
Here's a simple trick: you have to add en empty UIView
inside your UITableView
in Storyboard. The set the height = 0
.
The last separator of the UITableView
magically disappears.
Edit:
You will also need to edit your cellForRowAtIndexPath:
like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];
if (indexPath.row == [self tableView:tableView numberOfRowsInSection:[self numberOfSectionsInTableView:tableView]-1]-1) {
//this is the last cell
cell.separatorInset = UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0);
} else {
cell.separatorInset = UIEdgeInsetsMake(0, 0, cell.bounds.size.width, 0);
}
return cell;
}
Upvotes: 1
Reputation: 33036
Separator colour is a property of the table view, you can get or set it like so:
self.tableView.separatorColor = UIColor.blackColor()
But I don't think you cannot change the separator colours of a individual cell.
If you truly need that level of customization, you should probably just draw the separator bar yourself as, for example, a thin UIView
at the top of the cell. Then you can change its appearance to whatever you want.
Upvotes: 0