I have a UITableView with Custom Headers but I can't remove the bottom white line inside. The Separator property is set to none, in fact, the cells in the section don't have the line.
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
static NSString *CellIdentifier = #"DashboardSectionHeader";
UITableViewCell *headerView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
...
return headerView;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 60;
}
Have you checked DashboardSectionHeader cell?If there is a line at the bottom.Try changing the backgroundcolor of this cell and see.If the line is appearing in the section view ,then there should be say a one pixel space at the bottom of this cell through which the background will be visible.
I had the same issue in the same circumstances as you, and for me the problem have been solved by adding:
cell.contentView.clipsToBounds = NO;
in tableView: viewForHeaderInSection: method. Or you can just uncheck Clip Subview property in Attribute Inspector for your cells Content View (in Storyboard or xib file). FYI, I kept this property checked for my TableViewCell.
Related
I have a section with dynamic multiple rows and I need to separate all the section with the background as shown in the image below.
Specifically those border lines for all the section. Pease let me know how can I make it possible.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
return ProductArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *arr = [ProductArray objectAtIndex:section];
return arr.count;
}
Please refer to this
.
I tried adding header and footer, But I am not understanding how to add that rectangle box image for the entire section.
Put View in your cell after make outlet of that view. And use to cellForRowAtIndexPath this method.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"TableViewCell" forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.viewBackGround.backgroundColor = [UIColor redColor];
return cell;
}
For above requirement, I would like to suggest you the below approach.
create only one section with multiple rows.
Each row of UITableView will have UITableViewCell
Inside UITableViewCell create content view for which we are gonna add the border
Each row of UITableViewCell will have another UITableView(inside content view) whose methods are handled by UITableViewCell cells
Change UITableView (inside) height based on number of rows.
provide height of UITableViewCell based on the number of rows + orderID Header.
I have a UITableView with three Cell Prototypes in the storyboard, I use one cell in the header section, one for the normal table rows and another for the table footer.
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
static NSString *CellIdentifier = #"Header";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//some personalization
return cell;
}
My problem is whenever i enter in the edit mode of the tableview the header and footer are moving to the left, like the cell that is current editing.
- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
In edit mode:
Any solution or hints?
Neither the last XCode update fixed it.
Thank you
Solved. Basically I had to create a UIView and use that in as My header / footer, and not use a UITableViewCell.
Thanks to
Table Header Views in StoryBoards
and
Stick UITableView header view to top when creating header in storyboard
Along the way I found out that it's perfectly fine using a tableViewCell, you just return the cell contentView and the indention for the header while editing is gone.
I solved the issue of "moving" headers with creating a header with a UIView instead of UITableViewCell. You can do it by simply dragging a UIView out to the UITableView it will place it right above/between prototype cells. Then you can treat it as and view in Interface Builder. You can create a controller for it, but imho it is quicker and easier to give it a tag and then use tableView.viewWithTag(tag). Hope it helps!
I am using xcode6.0.1.In my UIVIew Controller contains one tableview and i need to set separator inset full width.I changed my tableview separator inset via xib.But i can’t get full width for separator inset on my xcode6 (In my xcode5 separator inset full width is possible).How to solve this issue?
change tableview separator inset via xib
my tableview separator line like this(not get full width)
I solved my issue
-(void)viewDidLoad{
self.tableView.layoutMargins = UIEdgeInsetsZero;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
Use this method in iOS 8 [tableView setLayoutMargins:UIEdgeInsetsZero];
I guess you simulated your app in iOS8 , this is a new property "#property(nonatomic) UIEdgeInsets layoutMargins " in iOS8. I suggest you try to create a UITableViewCell class category(e.g. UITableViewCell+Separator) then add this getter
- (UIEdgeInsets)layoutMargins
{
return UIEdgeInsetsZero;
}
in iOS7 this will not be called cos there's no this property in SDK,and will not cause any crash; in iOS8 this will be called every time you use the cell
It works for me
In my application i'm using custom cell in table view to display images in all rows. But in my .xib file there is a big empty space comes at the top of the custom cell. Can anyone tell me that how remove that space in iOS7 (iPad)? (like how to change the Y axis of the custom cell)
This is an IOS7 related issue with UITableViewStyleGrouped and size of footer views in section.
If you set the footerView to be size 0 it defaults to a larger value, The solution I found was to set the footer to a very small non zero number
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.0000001f;
}
Try to set into your property inspector like this..
This might help you:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectNull];
sectionHeader.hidden = YES;
return sectionHeader;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0;
}
Sometimes the empty space in the first row is the section header space. This functions eliminate it.
I have a UITableView configured as 'UITableViewStylePlain' with UITableViewCellSeparatorStyleSingleLine for its separator style. The cells have a background color.
The problem is that when you scroll the tableview, once some cells disappear off screen and are brought back, the separator is no longer visible.
The cells are registered with:
[tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
Cell code:
- (void)customizeMyTable
{
[self.tableView setDataSource:self];
[self.tableView setDelegate:self];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
NSString *cellIdentifier = [MyTableViewCell cellIdentifier];
UINib *nib = [UINib nibWithNibName:cellIdentifier bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
self.tableView.rowHeight = 50;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
[cell configure:someDataForThisRow];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor lightGrayColor];
}
Anyone experience this problem? This seems to happen only on iOS 5, not on iOS 6 Tableviews.
If you implemented layoutSubviews in your custom cell, and you accidentally forget to call the corresponding super method, you will not see the separator line.
Maybe you should check to see if you forget to call super in your other methods.
- (void)layoutSubviews
{
[super layoutSubviews]; //<-THIS LINE YOU NEED
//own code continues here
}
I've had to set the separator insets to 0 to stop the problem.
My problem also got solved by setting separator insets value 0.
If you build content of your UITableViewCell dynamically, please be sure that you add your subviews to contentView not to self:
contentView.addSubview(subView)
instead of
self.addSubview(subView)
It is related to LED screen resolution, since actual devices has very high resolution, the Monitor finds it hard to render those minute lines on the screen. It will work fine on actual device.
someone told me not to care of it. so you are fine with this if problem is only with simulator.
If its annoying to you then make a custom cell and put a separator into that and also remove the default separator from the cell by
For Obj.C:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Otherwise you should be fine when you will test on real device.
I have the same problem in swif. In my case, I found that the cells newly appear while scrolling overlap the others a little bit by clicking "debug by View Hierarchy" button. That's why separator lines disappear.
So the solution is quite simple, set the cell return in cellForRowAtIndexPath clipsToBounds = true so that it would not go out of the height you assigned and overlap the other cell's separator line.
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellView = tableView.dequeueReusableCell(withIdentifier: cellReuseId, for: indexPath)
cellView.clipsToBounds = true //Add this line
return cellView
}