使用两个tableviews和app崩溃时发生了竞争条件

时间:2017-10-13 05:19:18

标签: ios swift uitableview race-condition

我在uiview控制器上使用带有两个按钮的标签栏来显示两个不同的tableview。如果正常使用,一切正常。

但是当我滚动一个tableview并立即点击按钮切换到第二个tableview时出现问题。

我想由于竞争条件occor,因为一个tableview没有完成它的过程,我开始了第二个过程。

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

Windows -> Devices

1 个答案:

答案 0 :(得分:0)

在UITableView的委托功能中,您可以根据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()
  }
}

这种方式在继续之前,它将首先识别在哪个表视图上使用哪个数据源在哪个索引上工作