Black 1px line appearing between selected cells of a clear table - ios

Prior to Xcode 5.1 this problem didn't exist for me but now when building my app with 5.1/5.1.1 I'm seeing black horizontal lines appear when my table cells are selected. Both the table view and cells have clear backgrounds and nothing has changed in the code from the time it was working just fine.
In the viewDidLoad method I set the following tableView parameters:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor clearColor];
In the cellForRowAtIndexPath method:
ListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ListViewCell"];
if (cell == nil) {
cell = [[ListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"ListViewCell"];
}
return cell;
}
I'm using a UITableViewCell subclass which has the following in awakeFromNib:
UIView *bkgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
bkgView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
bkgView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.4f];
self.selectedBackgroundView = bkgView;
This code worked fine when building in version of Xcode < 5.1 but now I'm seeing different results. Occurs with both Plain and Grouped styles.

[self.tableView setSeparatorColor:[UIColor clearColor]];

Related

uitableviewcell disappears after rotating iOS device

I am facing problem for UITableViewCell
What I am doing,
Having three table views on 3 different views of same view controller of iPad.
Among which,
on 1st tableview I have cell with content view button and text.
Text+button is showing well when the app loads first time.
But as soon as I rotate the device the button+text disappears.
What I am doing wrong.
Thanks in advance.
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
}
if (tableView.tag == 1005)
{
if (indexPath.row == 0)
{
circle = [CAShapeLayer layer];
// Make a circular shape
circularPath=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 35, 35) cornerRadius:MAX(35, 35)];
circle.path = circularPath.CGPath;
// Configure the apperence of the circle
circle.fillColor = [UIColor blackColor].CGColor;
circle.strokeColor = [UIColor blackColor].CGColor;
circle.lineWidth = 0;
UIButton* cameraBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,0, 35,35)];
cameraBtn.backgroundcolor = [UIColor redColor];
[cell.contentView addSubview: cameraBtn];
cameraBtn.layer.mask=circle;
UILabel *photoLbl = [[UILabel alloc]initWithFrame:CGRectMake(50, 0, 150, 30)];
photoLbl.backgroundColor = [UIColor clearColor];
photoLbl.font = [UIFont fontWithName:#"OpenSans" size:16];
photoLbl.text = #"Take photo";
[cell.contentView addSubview:photoLbl];
[photoLbl release];
[cameraBtn release];
cell.contentView.frame = cell.bounds;
cell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
return cell;
}
I searched for all links on SO, but didn't get suitable solution.
Try upgrading your simulator , I had the same problem and it worked fine when I tested it in a real device.

TableView starts in the wrong position initially

This issue has come about as I update an app from iOS 7 to iOS 8. My tableview starts in the wrong position initially. Once you touch it or scroll it. The tableview scrolls into the correct position and works as intended.
The table view is embedded within a UIPageViewController.
UITableView *tableView = (id) [self.view viewWithTag:5];
[tableView registerClass:[BroadcastCell class] forCellReuseIdentifier:CellBroadcastTableIdentifier];
[tableView registerClass:[BroadcastHeaderCell class] forCellReuseIdentifier:CellBroadcastHeaderTableIdentifier];
[tableView setSeparatorInset:UIEdgeInsetsZero];
tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 64.0f)];
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 0.0f)];
[tableView setDelegate:self];
[tableView setDataSource:self];
tableView.backgroundColor = [UIColor clearColor];
tableView.opaque = NO;
tableView.backgroundView = nil;
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = UITableViewAutomaticDimension;
Screenshot can be found - https://pbs.twimg.com/media/Byh_5eIIQAA06ok.png:large
I had the same issue. After much effort I found out that in the previous view I was using
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"title-bar-bg.png"] forBarMetrics:UIBarMetricsDefault];
I changed it to
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"title-bar-bg.png"] forBarMetrics:UIBarMetricsDefault];
and the problem was solved.
Select your View Controller and Deselect property 'Adjust Scroll View Insets' on the storyboard (under View Controller section).
OR
Add following lines
self.automaticallyAdjustsScrollViewInsets = NO;

Label in UICollectionReusableView displayed only in even indexes

I have run into a very odd problem with UICollectionReusableView. My footer's are displaying correctly but the problem is with my headers.
My headers are a subclass of UICollectionReusableView and contain:
A UILabel on the left side
A UILabel on the right side
Both labels are initialized the same way with very similar properties in the initWithFrame method which is being correctly called.
Here is an example code section:
- (id)initWithFrame:(CGRect)frame
{
if((self = [super initWithFrame:frame]))
{
self.backgroundColor = [UIColor whiteColor];
titleLabel = [[UILabel alloc] initWithFrame:CGRectInset(frame, 10, 0)];
titleLabel.font = [UIFont boldSystemFontOfSize:24];
titleLabel.textColor = [UIColor blackColor];
titleLabel.backgroundColor = [UIColor clearColor];
[self addSubview:titleLabel];
dotCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(2 * frame.size.width / 3 - 5, 8, frame.size.width / 3, frame.size.height)];
dotCountLabel.textAlignment = NSTextAlignmentRight;
dotCountLabel.textColor = [UIColor blackColor];
dotCountLabel.backgroundColor = [UIColor clearColor];
[self addSubview:dotCountLabel];
}
return self;
}
The second label is being displayed without any problem but the first one in odd indexed sections is displayed on top of the label in the next section. For any of view that would like to see how I create these views:
SaveHeader *header = (SaveHeader *)[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:#"saveHeader" forIndexPath:indexPath];
Pattern *pattern = [saveModel.savedPatterns objectAtIndex:indexPath.section];
header.titleLabel.text = pattern.title;
header.dotCountLabel.text = [NSString stringWithFormat:#"%i dots", pattern.dotCount];
return header;
I have worked with these a bunch of times before and I have never run into anything like this. Anyone have an idea why this happening and how it could be fixed? Also note I have ran a debugger through it and the data object is returning the correct data. I am using iOS 7.1.
Before your initWithFrame calls, store the CGRect that you are about to init with into a variable and examine it. Look closely at the values. You'll likely find your bug there. Good luck!

UITableView separator line does not show in iPhone app

I have app in which i am using tableView problem is that when tableView has one record then it does not show separator line but shows when there are two records.
The first cell in tableView is textField. here is the code i am using.
for (UIView *subView in cell.subviews)
{
if (subView.tag == 2 || subView.tag == 22)
{
[subView removeFromSuperview];
}
}
tableView.backgroundView=nil;
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.separatorInset = UIEdgeInsetsZero;
if(indexPath.section==0){
tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,0,248,31)];
tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
tagInputField.textAlignment=UITextAlignmentLeft;
tagInputField.backgroundColor=[UIColor whiteColor];
tagInputField.tag = 2;
tagInputField.delegate = self;
tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing;
[tagInputField.layer setCornerRadius:5.0f];
[tagInputField.layer setMasksToBounds:YES];
tagInputField.layer.borderWidth = 0.3;
tagInputField.layer.borderColor = [UIColor darkGrayColor].CGColor;
tagInputField.font=[UIFont fontWithName:#"Myriad-Pro" size:8];
[tagInputField setText:#"Enter tag here "];
tagInputField.textColor =[UIColor grayColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[cell addSubview:tagInputField];
return cell;
}
if(indexPath.section==1) {
UIButton *crossButton =[[UIButton alloc]initWithFrame:CGRectMake(228, 8, 18, 18)];
crossButton.tag = 22; //use a tag value that is not used for any other subview
//crossButton.backgroundColor = [UIColor purpleColor];
crossButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Cross.png"]];
[cell addSubview:crossButton];
cell.textLabel.font =[UIFont fontWithName:#"Myriad-Pro" size:8];
cell.textLabel.textColor =[UIColor grayColor];
cell.backgroundColor=[UIColor whiteColor];
cell.textLabel.text =[tagArray objectAtIndex:indexPath.row];
[crossButton addTarget:self action:#selector(deleteCell:) forControlEvents:UIControlEventTouchUpInside];
[tagInputField setFrame:CGRectMake(5,0,248,31)];
tableView.backgroundColor=[UIColor whiteColor];
[tagInputField.layer setCornerRadius:0.0f];
[tagInputField.layer setMasksToBounds:YES];
tagInputField.layer.borderWidth = 0.0;
tagInputField.layer.borderColor = [UIColor clearColor].CGColor;
return cell;
}
When you will have only 1 record then separator will not show, and you should setting the separator for tableView at viewDidLoad look like
- (void)viewDidLoad
{
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
and in any case you want to show your own separator for every single cell ten try to add a imageView or somrthing witch share by the table cell
UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 1024, 1)];
separatorView.layer.borderColor = [UIColor redColor].CGColor;
separatorView.layer.borderWidth = 1.0;
[cell.contentView addSubview:separatorView];
How to customize tableView separator in iPhone
go for more on it....
Just try like this in side the Cell_for_Row_At_Index_path delegate method:
[tableView setSeparatorInset:UIEdgeInsetsZero];
[tableView setSeparatorColor:[UIColor greenColor]];
just paste this line and check.
add an empty footer at the end of the tableview to show the separator. To do so implement the following tableview delegate method in your class with your other tableview delegate functions:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001;
}
I used this to add last cell separator line....
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// To "clear" the footer view
UIView *separatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 1024, 1)];
separatorLine.layer.borderColor = [UIColor grayColor].CGColor;
separatorLine.layer.borderWidth = 1.0;
return separatorLine;
}
I found none of the above answers worked. I was particularly wary of the answer suggesting adding a UIView to look like the line.
In the end I found that this answer worked for me:
tableView.separatorStyle= UITableViewCellSeparatorStyleSingleLine;
In another answer it was suggested that adding worked better
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.separatorStyle= UITableViewCellSeparatorStyleSingleLine;
but I found that this was unnecessary.
All the credit goes to user859045 and samvermette for their answers on different threads. samvermette's thread especially has a lot of answers on this topic which are very helpful and worth a look.

Strange Behaviour of Selected UITableViewCell in iOS7

I am porting my application to iOS 7 and having some strange behaviour with my tableViews. When I select a cell, the separators disappear for no apparent reason. Not only that, but the background image for the selected state also shifts about 1 pixel upward, even though its frame does not indicate this. I have none of these issues with iOS 6 or older operating systems.
I define my table view the following way:
statisticsTableView = [[UITableView alloc] initWithFrame:CGRectMake(170.0f, 0.0f, 150.0f, window.size.height) style:UITableViewStylePlain];
statisticsTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
statisticsTableView.separatorColor = [UIColor darkGrayColor];
//statisticsTableView.separatorInset = UIEdgeInsetsZero; // <- Makes app crash in iOS6 or older
statisticsTableView.showsHorizontalScrollIndicator = NO;
statisticsTableView.delegate = self;
statisticsTableView.dataSource = self;
The cell is sub-classed and the relevant parts are the following (both regular and selected bacground images are the exact same size and appear correct in iOS6 or older, it is only iOS 7 where the selected BG image appears slightly higher):
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 70.0f)];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"cell_background_corp.png"]];
self.backgroundView = backgroundView;
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 70.0f)];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"cell_background_corp_selected.png"]];
self.selectedBackgroundView = backgroundView;
Now, I do know that other people had already asked this question (or, at least part of it), but none of the answers there worked for me. For further reference, I tried these "solutions" and they did NOT work:
Putting this into my didSelectrowAtIndexPath made my cells deselect.
But, I need my selected cell to stay selected, and besides
it looked really awkward with the blinking as swithces between states:
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
The other one:
Putting this into the heightForRowAtIndexPath delegate method
as a return value did absolutely nothing:
ceilf(rowHeight);
And finally:
This was my attempt to fix the background image position bug. I modified
the way I added the selected background view in the subclassed tableView cell,
but it did not do squat:
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 70.0f)];
if (iOSVersion >= 7.0f)
{
backgroundView.frame = CGRectMake(0.0f, 1.0f, 150.0f, 70.0f);
}
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"cell_background_corp_selected.png"]];
self.selectedBackgroundView = backgroundView;
I had a similar problem and what fixed it for me was to override layoutSubviews in the UITableViewCell subclass like this:
- (void)layoutSubviews
{
[super layoutSubviews];
self.selectedBackgroundView.frame = self.backgroundView.frame;
}
The important thing is to have the [super layoutSubviews]call first.
By the way, I think the default behavior is intended in iOS7. If you look at the Apple Mail app, you see that the separator line also disappears when selecting a cell and that the active background is drawn where the separator line used to be.

Resources