gpt4 book ai didi

ios - 使用两个 TableView 时发生竞争条件并且应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 12:05:29 25 4
gpt4 key购买 nike

我在 uiview Controller 上使用带有两个按钮的选项卡栏来显示两个不同的表格 View 。如果正常使用,一切正常。

但是当我滚动一个表格 View 并立即单击按钮切换到第二个表格 View 时,问题就出现了。

我猜由于竞争条件发生,因为一个 TableView 没有完成其过程,所以我开始了第二个过程。

有没有办法解决这个问题。

@IBOutlet var tableViewCase: UITableView!
@IBOutlet var tableViewInsp: UITableView!
@IBOutlet var tabBar: UITabBar!

var selectedTableView:UITableView!

func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
{
if item.tag == TAB_BAR_CASES {
app?.settings.lastSelectedInboxTab = ACTIVITY_KIND_CASE
selectedTableView = tableViewCase
presenter.refresh()

self.view.bringSubview(toFront: tableViewCase)
showSelectedTableView()
}
else if item.tag == TAB_BAR_INSP {
app?.settings.lastSelectedInboxTab = ACTIVITY_KIND_INSP
selectedTableView = tableViewInsp

presenter.refresh()

self.view.bringSubview(toFront: tableViewInsp)
showSelectedTableView()
}
refreshTable(selectedTableView)
}

最佳答案

当您在 UITableView 的委托(delegate)函数中不基于 tableView 的实例进行处理时,这是可能的。例如,像这样处理应该会有所帮助:

func numberOfSections(in tableView: UITableView) -> Int {
if(tableView == myTableView1) {
    return myTableview1DataSourceRowCountVariable
}
else if(tableView == myTableView2) {
    return myTableview2DataSourceRowCountVariable
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
if(tableView == myTableView1) {
    return myTableview1SectionCountVariable
}
else if(tableView == myTableView2) {
    return myTableview2SectionCountVariable
}
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(tableView == myTableView1) {
    return PrepareMyCellForTableView1()
}
else if(tableView == myTableView2) {
    return PrepareMyCellForTableView2()
}
}

这样,在继续之前,它将首先识别正在处理的哪个 TableView 使用哪个数据源以及哪个索引 .

关于ios - 使用两个 TableView 时发生竞争条件并且应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46722985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com