Reputation: 20130
I have an cell class that is inherited from UITableViewCell
. It has next grey lines:
However if I don't set cell texts I don't see these lines:
So what can be the cause for this lines?
UPDATE
Here is code for my custom cell:
@implementation MDItemTableViewCell
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
NSString *fontName = selected ? self.selectedFontName : self.fontName;
self.textLabel.font = [UIFont fontWithName:fontName size:self.fontSize];
}
@end
UPDATE 2
Here is code for cellForRowAtIndexPath
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *source = [(MDChoiceField *)self.field source];
MDChoiceItem *item = source[(NSUInteger)indexPath.row];
MDItemTableViewCell *cell = [(MDItemTableView *)self.fieldView cellForRowAtIndexPath:indexPath];
cell.textLabel.numberOfLines = 0;
NSString *string = NSLocalizedString(item.title, nil);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]
initWithString:string];
[attributedString addAttribute:NSKernAttributeName
value:@(1.2)
range:NSMakeRange(0, [string length])];
cell.textLabel.attributedText = attributedString;
return cell;
}
And view one:
- (MDItemTableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MDItemTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.font = [UIFont fontWithName:self.fontName size:self.fontSize];
cell.fontSize = self.fontSize;
cell.fontName = self.fontName;
cell.selectedFontName = @"HelveticaNeue-Light";
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [UIColor colorWithHexString:BLUE_COLOR];
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds];
cell.selectedBackgroundView.backgroundColor = [UIColor colorWithHexString:LIGHT_BLUE_COLOR];
return cell;
}
Sorry for so many lines.
Upvotes: 4
Views: 199
Reputation: 699
Note that the added lines are shorter than the table cell itself. If you turn on "Color Blended Layers" in the simulator Debug menu you can see that they seem to be the same length as the label. This suggests it's the label, not the cell, which is producing the oddity.
This question seems related: How can I remove UILabel's gray border on the right side?
And that suggests the following fix, added to cellForRowAtIndexPath:
:
[cell.textLabel setBackgroundColor:[UIColor clearColor]];
Upvotes: 2
Reputation: 1578
Those lines are the default separator lines of tableView. Just set the separator style as NONE. write or use this line wherever you have declared your UItableView. Either in Xib file or code.
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Update:1
- (void)viewDidLoad { [super viewDidLoad];
// This will remove extra separators from tableview
self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
}
Use this, and let me know if it works or not.
Upvotes: 0
Reputation: 5169
Using a 'Grouped' style UITableView will keep the table from showing these 'blank' cells if they are in fact empty. You can either declare this when you init the UITableView like this,
UITableView *myTable = [[UITableView alloc] initWithStyle:UITableViewStyleGrouped];
Or if you're using interface builder there's a drop down to change the style from 'Plain' to 'Grouped'
Upvotes: 0
Reputation: 27052
A few settings will help you,
As Richa's answer, self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
It'll hide seperator (default one) from the table.
As user3781721 answer, tableName.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
will remove any empty cell. So there'll be a plain look of table.
In tableview's cellForRow datasource, cell.clipsToBound = YES;
before return the cell.
If still not solve then increase your cell height little, may be by 5 and check.
Upvotes: 2
Reputation: 576
Put this code in ViewDidLoad
tableName.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Upvotes: 0