【发布时间】:2018-09-05 06:35:20
【问题描述】:
当表中没有项目时,我实现了一个子视图,它显示在 UITableViewController 的表视图上。添加项目后,子视图从父视图中移除以显示表格视图,但单元格已变为不可选择。此外,点击编辑按钮后作为导航项出现在左侧的删除圆圈按钮⛔️对点击无响应。
有趣的是,向左滑动可删除作品。并向左滑动以显示删除框,然后按下该框即可。确实很奇怪的行为。这就是我所拥有的:
override func viewDidLoad() {
super.viewDidLoad()
// Check if there are any items in the fetchedResultsController. If empty, present noDataScreen over the tableView
if fetchedResultsController.fetchedObjects!.count == 0 {
let noDataScreen = EmptyTableView.init(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
view.addSubview(noDataScreen)
}
// Item Search View Controller Delegate
func itemSearchViewController(_ controller: ItemSearchViewController, didFinishAdding item: Item) {
if fetchedResultsController.fetchedObjects!.count != 0 {
if let viewWithTag = self.view.viewWithTag(1000) {
viewWithTag.removeFromSuperview()
}
}
}
// I was hoping the code below would reset the state of the tableview after the subview, the noDataScreen, is removed to allow for tableview row selection
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tableView.dataSource = self
tableView.delegate = self
tableView.reloadData()
}
我尝试了以下代码:
// Revised viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.becomeFirstResponder()
// I moved the if and if-let statements here since this will be invoked as the popover Item Search View Controller is dismissed.
if fetchedResultsController.fetchedObjects!.count != 0 {
if let viewWithTag = self.view.viewWithTag(1000) {
viewWithTag.resignFirstResponder()
viewWithTag.removeFromSuperview()
}
self.view.isUserInteractionEnabled = true // enable interaction with the tableview to return everything to normal, hopefully
self.navigationItem.leftBarButtonItem?.isEnabled = true
}
}
// Added
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.view.becomeFirstResponder()
}
仍然无济于事????。不知何故,在父视图上添加子视图会影响 tableView 的触摸功能,它是 UITableViewController 的一部分。任何想法将不胜感激。
【问题讨论】:
标签: uitableview tableview swift4 xcode9 addsubview