All UITableCells disappear when tapping on UITableView in iOS 7
I experienced the exact same problem. The issue was that I was using a custom datasource class (called tableVCDataSource), and was setting the tableView's dataSource incorrectly in the ViewController class. I was doing:
override func viewDidLoad() {
mainTableView.dataSource = TableVCDataSource()
}
when I should have been doing:
fileprivate var tableVCDataSource: TableVCDataSource?
override func viewDidLoad() {
tableVCDataSource = TableVCDataSource()
mainTableView.dataSource = tableVCDataSource
}
This solved my issue.
In swift you need to declare viewcontroller object globally that would result in Strong, in case if you declare locally it results in keep disappearing the cells.
e.g.
var refineViewController : RefineViewController?
then you can access that controller using below code that would not result in disappearing cells.
func showRefineView(isFindHomeTab isFindHomeTab : Bool){
refineViewController = RefineViewController(nibName: String(BaseGroupedTableVC),bundle : nil)
refineViewController!.refineSearchDelegate = self
refineViewController!.view.frame = CGRectMake(0, -490, self.view.frame.size.width, self.view.frame.size.height)
UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveEaseOut, animations:
{
self.refineViewController!.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
self.refineViewController!.isFindHomeTab = isFindHomeTab
}, completion: nil)
self.view.addSubview(refineViewController!.view)
}
When you display the UITableView
in a different view, you must always make sure that the view controller which "hosts" the UITableView
has a strong reference to its controller. In your case, the data source for the UITableView
seems to be deallocated after adding the UITableView
as subview.
Changing the currentViewController property from weak
to strong
should fix your problem.