Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 502 Vote(s) - 3.61 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to remove empty cells in UITableView?

#1
i am trying to display a simple `UITableView` with some data. I wish to set the static height of the `UITableView` so that it doesn't displays empty cells at the end of the table. how do I do that?

code:



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%d", [arr count]);
return [arr count];
}
Reply

#2
In the Storyboard, select the `UITableView`, and modify the property Style from `Plain` to `Grouped`.
Reply

#3
Implemented with swift on Xcode 6.1


self.tableView.tableFooterView = UIView(frame: CGRectZero)
self.tableView.tableFooterView?.hidden = true



The second line of code does not cause any effect on presentation, you can use to check if is hidden or not.

Answer taken from this link

[To see links please register here]

Reply

#4
I tried the code:

tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

In the **viewDidLoad** section and xcode6 showed a warning. I have put a "self." in front of it and now it works fine. so the working code I use is:

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

Reply

#5
**Using `UITableViewController`**

The solution accepted will change the height of the `TableViewCell`. To fix that, perform following steps:

1. Write code snippet given below in `ViewDidLoad` method.

`tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];`

2. Add following method in the `TableViewClass.m` file.



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return (cell height set on storyboard);
}

That's it. You can build and run your project.
Reply

#6
override func viewWillAppear(animated: Bool) {
self.tableView.tableFooterView = UIView(frame: CGRect.zeroRect)

/// OR

self.tableView.tableFooterView = UIView()
}
Reply

#7
or you can call tableView method to set the footer height in 1 point, and it will add an last line, but you can hide it too, by setting footer background color.

code:

func tableView(tableView: UITableView,heightForFooterInSection section: Int) -> CGFloat {
return 1
}

[looks like last line][1]


[1]:
Reply

#8
in the below method:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (([array count]*65) > [UIScreen mainScreen].bounds.size.height - 66)
{
Table.frame = CGRectMake(0, 66, self.view.frame.size.width, [array count]*65));
}
else
{
Table.frame = CGRectMake(0, 66, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 66);
}
return [array count];
}


here 65 is the height of the cell and 66 is the height of the navigation bar in UIViewController.
Reply

#9
**Swift 3 syntax:**

tableView.tableFooterView = UIView(frame: .zero)

**Swift syntax: < 2.0**

tableView.tableFooterView = UIView(frame: CGRect.zeroRect)

**Swift 2.0 syntax:**

tableView.tableFooterView = UIView(frame: CGRect.zero)
Reply

#10
Set a zero height table footer view (perhaps in your `viewDidLoad` method), like so:

**Swift:**

tableView.tableFooterView = UIView()

**Objective-C:**

tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];


Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for.

**Interface builder pro-tip:**

If you are using a **xib/Storyboard**, you can just drag a UIView (with height 0pt) onto the bottom of the UITableView.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through