In my app I have a UITableView
with 5 cell data. When I will run the app. It will display 5 cells with data properly in Output. But there are many extra cell show empty. I want to remove extra cell in UITableView
. I have also done in objective-C but I need some help in Swift 2.2 also I'm new in swift.
in your viewDidLoad()
add this line :
yourtableView.tableFooterView = UIView()
or use
yourtableView.tableFooterView = UIView(frame: CGRectZero)
The issue might be arising from the fact that you are specifying a greater number of rows in the UITableView
than required to populate data. Assuming you are populating the UITableView
from an Array, you should probably set the row count to the count of array.
If you are using a UITableViewController
override this method
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
If a UITableView
is embedded in the UIViewController
set UITableView
delegate to self and implement this method.
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
Try the following code. May be this is helpful to you.
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
}
编写这段代码
self.tableView.tableFooterView = UIView(frame: CGRectZero)
Implement this delegate method like this:
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.