this is my grouped tableview:
Is it possible to avoid the spacing between sections and display the grouped table as if there is no sections?
Thanks in advance, yassa
Probably not what you want to hear, but no. No nice way to do this. I Think you are able to minimize the Space between the Groups but this will look very bad.
Another way would be to use one Section, but then you wont have this nice little Letters at the right side.
But if you want no Space between the Cells why dont you use UITableViewPlainStyle?
It appears that you don't have any content for header or footer in your table view, so I think you could achieve that by implementing table view's delegate methods :
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
Those two methods might work correctly if you also implement :
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
returning nil for each.
In iOS 7 I customized space between sections in grouped table view by implementing next method:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 10; // there might be your height
}
To make this method work prior to iOS 5, you should also return non-nil view in tableView:viewForFooterInSection:.
Prior to iOS 5.0, table views would automatically resize the heights
of footers to 0 for sections where tableView:viewForFooterInSection:
returned a nil view. In iOS 5.0 and later, you must return the actual
height for each section footer in this method.
Related
I have UITableView that contains 4 different types of customized cells in storyboard. Each cell has customized UILabels which get variable amount of text data from backend. I am struggling with making the cells resizing correctly. I would really want to change the height of each cell but I can not use heightForRowAtIndexPath because it is called before cellForRowAtIndexPath, but the height is actually calculated within each customized cell.
I tried writing in each cells' height into an array while the UITableView is loading, then just reloading it all over again once, but no effect. I tried using CGFloat rowHeight = UITableViewAutomaticDimension with no success either. The customized labels in each cell definitely grow with text which I see when I just statically change row height to higher numbers. So, I would need somehow my labels to push on rows to make them grow, not sure.
Different similar posts on stackoverflow that I found did not help.
The issue was that I needed to set up top and bottom constraints to the ContentView and NOT to the cell itself in the storyboard.
Label -> ContentView top and bottom constraints need to be set up. And then UITableViewAutomaticDimension specified in viewDidLoad:
self.tableView.rowHeight = UITableViewAutomaticDimension;
estimatedRowHeight should be set too. For example:
self.tableView.estimatedRowHeight = 76.0f;
First Method called is:
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
Second:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Then:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
set a break point in the above methods and test it. So if you want to preset the height use estimatedHeightForRowAtIndexPathmethod.
I'm using Autolayout on iOS 8 and make use of UITableViewRowAnimationAutomatic and all of its magic.
When the Tableview appears the cells have a wrong height and the subviews are distributed over the whole cell with a lot of horizontal space between them. When I scroll down or rotate the device and back alls cells are drawn correctly with the correct size.
Debugger says no error and Autolayout warnings are not present.
These cells are only drawn on iPad and I have specified only for sizeclass (Regular | Regular).
Do you any hints what could be the problem?
There are three things that you need to make sure you are doing...
The AutoLayout Constraints should cover the entire height of the cell. So just by looking at the constraints you should be able to say exactly how tall the cell is.
Implement the estimated height for row method...
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// return an actual number here. This is a guess of how tall the cells are
return 100;
}
or
// Thanks #rdelmar :-)
self.tableView.estimatedRowHeight = 100;
Implements height for row...
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// return auto dimension here
return UITableViewAutomaticDimension;
}
Once you have done all three of these it will work.
See my blog here for more data (note, there has been an update since I wrote the blog which I haven't updated yet).
http://www.oliverfoggin.com/using-a-static-uitableview-as-a-layout-device/
I am trying to disable part of the UITableView cell. Please see image below.
This white part is a view in my cell. I don't know how to disable it, so that when user taps it nothing will happen. Maybe some king of mask?
Moving this out of the comments section. If you want padding between your cells what you should do is make each row its own section and use the delegate method
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section
However, this method will not be called if your tableview is the default style. So, set your tableview style to UITableViewStyleGrouped
Then you have to implement the delegate methods so that you return a height for the footer and make sure that each row gets its own section:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//Return however many rows you have specifically or the count of the datasource
return [array count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
CGFloat myHeight = 50.0 //your height here
return myHeight;
}
Implementing these three delegate methods like this should add a nice transparent padding between your cells.
Try this simple approach.Place a button on top of custom table view cell to mask the area which you want to be un-clickable. This acts as a mask on top of tableview cell which stops calling row did select delegate method. If you want to add any action for button click event add a method to button by passing row index.
well my issue is:
I want to have table view but I want to keep first cell always first , and never let it scroll
but other cells should scroll.
can someone please suggest me how to do so ?
If your table have only one section than create custom view like cell and add this view in
table delegate method
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
like
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return <Your View>
}
but it works if and only if one section in given in table.
The above answer with the static cell in the header works.
You might want to create another tableview just above the present one, with just static cells in it. Just below this table view, keep the present one with (number of all cells - number of static cells) without any offset. It looks as just one table view. This way, you can have more than one static cell with all the properties of a Tableview cell.
To specify cell heights of a table view we use the delegate method,
- (CGFloat) tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
However this method asks cell height of every row, what can I do if I want some of them to be defaults?
For cell height we may return UITableView#rowHeight for those default rows inside the delegate method, but I also want some (not all) of the section headers/cell to be customized.
But I am not able to get the defaults from the table view, especially for grouped style table view, anyone has a solution?
Thanks!
EDIT: I'm sorry for not making it very clear. In fact, cell height is not the only one that I want to partially customize, but also something else like section header (there may be more, like delete button style, etc.).
Is there solution without mimicking default behavior?
if you don't want default behavior in all cases, you'll still have to mimic default behavior in the non-specialized cases.
for headers, you will still have to implement
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
and therein, you will have to answer the default height for those headers you do not wish to change, and the specialized header height for those you do want to change.
similarly, in
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*);
you will still have to mimic default behavior for those cells you do not wish to change.
you could accomplish all of this with storyboard if you want: create specialized cells with unique identifiers for each, and then return the cell heights that go with them. if you take this route, then you may be able to get away with just using dequeueReuaableCellWithIdentifier and using the height value for that identifier. just use a unique cell identifier with a height that's appropriate for each cell you're thinking of.
The default height of cell is 44 .. so you can return it when your condition is not satisfied ..
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (YOUR_SPECIFIC_CONDITION) {
return 180.0;
}
return 44.0;
}
May this will help you..
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0 && indexPath.section==0)
{
return 180.0;
}
else
{
return 44.0;
}
}