Hide the tablecells in UITableView in Iphone - ios

In my application I would like to hide the table cells in uitableview , and I don't want to hide the header of the tableview in iPhone. On that table view header I would like to add a button, so if anyone know this how to hide the cells in a tableview without hiding the header in tableview in iphone.

If you want to hide all cells in a section, just set the number of rows in that section to 0!

Use table Dalegate method put height of that row 0.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

Related

UITableView footer overlaps cell in iOS 11

In my tableView, I am using automatic row & section footer height. It looks good on iOS 10, but on iOS 11 the section footer overlaps the cell on landscape.
Is there some new iOS 11 property that I'm not setting that's causing this?
This is what it looks like running on iOS 10:
This is what it looks like running on iOS 11:
I have xib with a tableView constrained to the edges of the view. I'm setting row/footer/header height in IB:
Do you set your custom heights for header and footer?
Your table view delegate should implement this methods:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
which should return appropriate values.
If you return smaller values then your header and footer views have, then they may overlap.

UITableView Rows Height After Loading Cells

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.

UItable Footer View issue

In my app I need to design the view with header, content view (table view) and footer view which is scrollable. Content view data will change dynamically. So I have used table view.
I have added the Header and footer view in the table view header and footer. (My goal is to scroll the header, content and footer view so the I have added my custom header and footer view in UItable view header and footer.)
My design:
It's working as per the design if the table view contains some data. Issue is, if table view doesn't contains any data (row count simply 0). The header view is display in the middle of the view (Table view frame shrink automatically in this case). Even I tried to handle the table view frame based on the data source count. But I can't.
How can I fix this issue?
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
You can use this code to customize footer height of UItableview
by putting valid if else
In a UItableView,The footer always appears at the end of section .But here you don't have any existance of cells and you want to show the footer at the bottom of the page .
Solution:
Take one cell before getting data and set the height for that cell
BOOL hasData;//Initialise in ViewDidLoad and set value according to data
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (!hasdata) {
return 1;
}else{
return dataArray.count;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (!hasData) {
cellHeight =
self.view.frame.size.height -
(tableViewHeaderHeight+tableViewFooterHeight);
}else{
//Set row height
}
}
and then after getting data for the tableview again reload that .
Hope this help you.Try this .It worked for me.
Table view sections have a header view and a footer view. Between those are the cells for that particular section. It sounds like you want to simulate the existence of cells that don't really exist.
Perhaps what you really want is a standard UIView as your header and footer views with a UITableView in between. The UITableView won't change size based on its content and will scroll when independently of the header and footer views.

Table view first cell always same

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.

Table view cell expandable iOS

I want a table view with only cels, and when you click on a cell it should expand and show more info of the clicked cell.
I've seen quite some topics on this, but the most of them are linking to Table View Animations and Gestures on the apple developer page. Which does it in a different way. They use header sections, but I want to use the cell which is expandable for layout reasons.
I already tried several things mainly with
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isSearching && indexPath.row == selectedIndex) {
return 110;
}
else {
return rowHeight;
}
When I Click on the cell, the cell is expanded but the info in that cell stays the same. Also the heigth of the cell when expanded should be related to the amount of text in the details.
Thnx!
You can achieve this through the use of custom cells. Create two custom cells, one for the normal row and other for the expanded row. When the user touches a particular cell, you can record it's indexPath and reload the tableView. While reloading you can change the height of this selected row using the code that you've just posted(increasing the height of only the selected cell). This would give an effect of expanding cell.

Resources