问题描述
我在主视图中使用tableView创建了splitView,在两个详细信息视图中使用了静态单元格创建了tableView(请参见图片).应用程序结构
I create splitView with tableView in master View and tableView with static cells in two details view (see on picture).App Structure
视图控制器的名称为:DocsTableViewController-主视图(在左侧)DocDetailTableViewController-详细信息视图(在右上角)DocEditTableViewControler-第二个详细视图(在右下角)
Names of view controllers are:DocsTableViewController - master view (on the left)DocDetailTableViewController - detail view (on the top right)DocEditTableViewControler - second detail view (on the bottom right)
DocsTVC是医生列表,DocDetailTVC是在DocsTVC中选择的医生用户的详细信息,在DocEditTVC上,用户可以编辑DocDetailTVC中显示的医生的数据或添加全新的医生(基于用户单击编辑"或添加"按钮).
DocsTVC is list of doctors, DocDetailTVC is detail of doctor user selected in DocsTVC and on DocEditTVC user can edit data of doctor showed in DocDetailTVC or add completely new one (based user clicked on edit or add button).
所有这些功能都可以正常工作-显示详细信息,显示编辑表单并保存已编辑的文档或新文档.问题是主表视图.保存/编辑过的新项目后,我尝试重新加载详细信息,通过print
,我看到数据已重新加载,但表未加载.表格显示仍然相同,我必须转到应用程序的其他屏幕,然后返回以查看重新加载的表格视图.我该怎么办?
All these things are working fine - show detail, show edit form and save edited or new doc. Problem is the master table view. I'm trying to reload it in detail after saving edited/new item and by print
I see that data are reload but not the table. Table is showing still the same and I have to go to same other screen of app and then go back to see reloaded table view. What should I do?
在DocEditTVC上保存了医生之后,我将再次详细介绍这种方法:
After saving doctor on DocEditTVC I'm going back to detail to this method:
@IBAction func saveToDocViewController (segue: UIStoryboardSegue){
let controller = DocsTableViewController()
controller.tableView.reloadData()
print("[SPLIT VIEW] detail: \(controller.docs.count)")
}
还有DocsTableViewControler(主视图)中的一些代码:
And some codes from DocsTableViewControler (the master view):
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
// menu
if inputsMenuButton != nil {
inputsMenuButton.target=self.revealViewController()
inputsMenuButton.action=#selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
// navigation bar
self.navigationController?.navigationBar.barTintColor = OAKScolor().colorOAKSmain()
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
// data load
print("[SPLIT VIEW]: ViewDidLoad")
dataLoad()
self.tableView.reloadData()
// split view
self.splitViewController?.delegate = self
self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
}
和
func dataLoad() {
print("[SPLIT VIEW]: DataLoad")
let arrayOfDocIDs = PlistManager.sharedInstance.getArrayOfValuesFromDict("DocID") as [AnyObject] as! [String]
for id in arrayOfDocIDs {
docs.append(DocData(docID: id).docLoad(false))
}
print("[SPLIT VIEW] table: \(docs.count)")
}
通过这些print
,我看到晚上进行得很顺利-视图确实加载到了主视图上,并且文档数组写入了新的计数.但是tableView并没有改变.谢谢您的帮助.
By these print
s I see that evening is going well - view did load on the master view and array of docs write new count. But the tableView is not changed. Thank you for any help.
推荐答案
使用此代码
let controller = DocsTableViewController()
controller.tableView.reloadData()
您创建了新的主控制器实例,而不是当前实例.有两种解决方法:
You created new Master controller instance, not the current one.There is 2 ways to solve it:
-
在详细控制器中,创建对当前主控制器的引用.
In Detail Controller, create a reference to current master controller.
使用代理.这是一个很好的解释: https://www.natashatherobot.com /explaining-ios-delegates一个关于您的早晨咖啡的故事/#
Use Delegate. Here is a good explanation:https://www.natashatherobot.com/explaining-ios-delegates-a-story-about-your-morning-coffee/#
希望获得帮助!
这篇关于SplitView-根据迅速更改的详细信息在主tableView中重新加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!