Draw a vertical separator on a UITableViewCell

I had a simple UITableView, and the cells are a subclass of UITableViewCell.

In a cell subclass, I overridden drawRect to insert this drawing code (for the vertical separator):

CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(c, [[UIColor grayColor] CGColor]);
CGContextBeginPath(c);
CGContextMoveToPoint(c, self.frame.size.height + 0.5f, 0);
CGContextAddLineToPoint(c, self.frame.size.height + 0.5f, self.frame.size.height);
CGContextStrokePath(c);

He did a great job. However, now I have changed the style of tableview to grouping. The line is simply not drawn. Although the breakpoint settings show the drawRect method, it is called.

I would like to avoid subclassing UIView just to draw a small row, especially since I have already subclassed the tableview cell, and I just want to draw it. So why does the code suddenly stop working on a grouped table view?

+5
source share
1 answer

drawRect UITableViewCell. backgroundView, UIView 1px.

UIView* vertLineView = [[UIView alloc] initWithFrame:CGRectMake(80, 0, 1, 44)];
vertLineView.backgroundColor = [UIColor redColor];
[self.contentView addSubview:vertLineView];
+10

All Articles