几乎所谓的标题:DidSelectRow
没有被调用,我确实检查了我没有使用Deselect
。我还检查了delegate
和DataSource
与tableViewController
有关,而Selection
是Single Selection
。但是,该方法仍未被调用。
一个空的tableView
可能对它有任何影响(因为它是空的是因为用户开始填充它。我正在使用CoreData
)?
编辑
这是方法的样子:
var effectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
var effect: UIVisualEffect!
let defaults = UserDefaults.standard
var userMagazineTitle = [User]()
var dataString = String()
override func viewDidLoad() {
super.viewDidLoad()
addProgrammatically()
let fetchRequest: NSFetchRequest<User> = User.fetchRequest()
do{
let users = try PresistanceService.context.fetch(fetchRequest)
self.userMagazineTitle = users
self.tableView.reloadData()
}catch{
ProgressHUD.showError("Nothing to see here")
}
}
/ MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return userMagazineTitle.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) as! MyFeedTableViewCell
cell.myHeadline?.text = userMagazineTitle[indexPath.row].title
cell.indentationLevel = 3
return cell
}
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
let manage = PresistanceService.persistentContainer.viewContext
let del = userMagazineTitle[indexPath.row]
if editingStyle == .delete {
// Delete the row from the data source
manage.delete(del)
do{
try manage.save()
}catch{
ProgressHUD.showError()
}
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "User")
do{
userMagazineTitle = try manage.fetch(fetchRequest) as! [User]
}catch{
ProgressHUD.showError()
}
tableView.reloadData()
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "showUser", sender: indexPath)
navigationController?.navigationBar.isHidden = false
tableView.deselectRow(at: indexPath, animated: true)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showUser" {
let DestViewController = segue.destination as! UINavigationController
let targetController = DestViewController.topViewController as! CompanyTableViewController
let indexPath = sender as! IndexPath
let user = userMagazineTitle[indexPath.row].title
let user2 = userMagazineTitle[indexPath.row].rssurl
targetController.customUserInit(articlesindex: indexPath.row, title: user!, rssUrl: user2!)
}
}
func addProgrammatically() {
effectView.frame = view.bounds
tableView.addSubview(effectView)
effectView.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
effectView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
} else {
// Fallback on earlier versions
effectView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0).isActive = true
}
effectView.heightAnchor.constraint(equalTo: self.view.heightAnchor).isActive = true
effectView.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true
effect = effectView.effect
effectView.effect = nil
self.tableView.separatorStyle = .none
tableView.backgroundView = UIImageView(image: UIImage(named: "myMagazines.jpg"))
tableView.backgroundView?.contentMode = .scaleAspectFill
tableView.clipsToBounds = true
navigationController?.navigationBar.isHidden = false
UIApplication.shared.statusBarStyle = .lightContent
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barStyle = .black
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
}
}
您已在tableview上添加了UIVisualEffectView
视图,该视图未将触摸事件传递给tableview。
设置effectView.isUserInteractionEnabled = false
,应该使此视图将触摸事件传递给下面的视图。
这个问题可能有两个问题:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
ObjectiveC: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath