简体   繁体   中英

swift - there is a cell in the empty tableview

I have several tableviews, one of them uses coredata and others get data from a json api. In my tableview which gets data from coredata, when I launch the app there is a cell, but my coredata is empty. Cell disappears when I reload the table. How am I going to remove that cell?

You could simply add code to erase all cells if your core data is empty. You do this in the ViewWillAppear(), if your core data object is empty then return 0 at your numberOfRows in table.

You could also add a self update function (by NSNotifications) which reads the current amount of data (count) and then do a reloadData() call.

These are only suggestions... we don't really know how your code looks like to be able to suggest a better answer.

Cheers

You can simply add the following line of code in viewDidLoad() or viewWillAppear() to clear unwanted cells from UITableview.

tableView.tableFooterView = UIView(frame: CGRectZero)

If Table is initially empty then there will be no cell to display.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM