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.
Related
I have to set spacing between each tableview cell say of 36 pts .I am using tableview rather than custom cell for creating the cell?
You can do this by having number of sections equal to number of items to display. Each section will contain only one row. You will then return transparent header for every section which will give illusion of cell spacing.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return <Your items count>;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return cellSpacingHeight;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView * headerView = [UIView new];
[headerView setBackgroundColor:[UIColor clearColor]];
return headerView;
}
A table view isn't like a collection view with a complex and capable layout specification, you can't specify arbitrary layouts and spacings.
So, use a collection view, or, if you want to continue with a table view, use a custom cell and add an empty section into each cell. Set the height of your cells to an appropriate value.
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.
I have a UITableView and there are 10 rows (This is a dynamic table, so more rows will be loaded).
Each cell/row should have the height of the full screen. There are different screen sizes in iOS now.
Therefore i am not able to give a fixed height for cell row as iOS devices have varying heights.
So how can I make a cell height to fit the screen height ?
If your tableView is in a ViewController then you can use this code below:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return CGRectGetHeight(self.view.bounds);
}
Else if your screen covers full screen, then use this
return CGRectGetHeight([[UIScreen mainScreen] bounds]);
Else if your screen contains a Navigation Bar as well, then use
return CGRectGetHeight([[UIScreen mainScreen] bounds] - 64.0f);
Or the Best Solution would be perhaps
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return CGRectGetHeight(tableView.bounds);
}
Edited
Its better to use rowHeight property instead of the delegate. Reason discussed below:
There are performance implications to using
tableView:heightForRowAtIndexPath: instead of rowHeight. Every
time a table view is displayed, it calls
tableView:heightForRowAtIndexPath: on the delegate for each of its
rows, which can result in a significant performance problem with table
views having a large number of rows (approximately 1000 or more).
Thanks to rdelmar
Source
How about this?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.view.frame.size.height-yourTableViewStartingYPosition;
}
If it's full screen it will be return self.view.frame.size.height
I found this question answered earlier on stack overflow and on other sites too. I tried all options, but yet their is white space below the table. I have 4 prototype cells in my tableview. On storyboard, their is no white space after the 4th cell. But on execution I find white space after the 4th row. Their is no more separator after 4th row, but blank white are is still their.
I tried adding the following code :
- (void)viewDidLoad {
[super viewDidLoad];
_menuItems = [[NSMutableArray alloc] initWithObjects:#"chats", #"visitors", #"agents", #"profile", nil]; //#[#"chats", #"visitors", #"agents", #"profile", nil];
self.tableView.tableFooterView = [UIView new]; //[[UIView alloc] initWithFrame:CGRectZero];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.menuItems count];
}
-(CGFloat)tableView:(UITableView *) tableView heightForFooterInSection:(NSInteger)section {
return 0.01f;
}
-(UIView *)tableView: (UITableView *) tableView viewForFooterInSection:(NSInteger)section {
return [UIView new];
}
To make the whole view look proper, I have set same background color for view and tableview. Everything looks proper except this white area,
Can anyone help me know why do I still l see white area after the last row ? Any help is highly appreciated. Thanks.
MY RowHeight of TableView (44) and TableViewCell (51) was different. I changed the RowHeight of TableView to 51.
And made the Height of TableView which was 220 to 204 (51*4).
Making the RowHeight same and setting tableView Height exactly as RowHeight * number of Rows works for such kind of problem as solution.
Hope this helps someone.
I'm using a custom header view for the section headers in a UITableView. Here are a couple of dataSource methods:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
SBTableViewHeader *header = [[SBTableViewHeader alloc] init];
header.titleLabel.text = self.earnings;
header.subtitleLabel.text = #"You have earned $23 today.";
return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 90;
}
I know that my header view is supposed to be 90 points high, but instead I'm getting 90 points of my header view PLUS another 90 empty points of space, which cover some of the cells. That's 180 total, measured it in Photoshop.
Help!
Some more info: SBTableViewHeader is a UIView subclass and is using a .xib. Nothing special there. File's Owner is set to SBTableViewHeader and everything else seems to be connected properly.
(From the comments:)
You have to use initWithFrame instead of init to create a view with the correct size.
heightForHeaderInSection: (and similarly heightForRowAtIndexPath) is used by the table view only to compute header and cell positions, the size of the scroll indicator etc.
The data source (or delegate) methods have to return cells/views of the correct size, otherwise they will overlap with other items.