ios - 两个 TableView 一个数据源?

标签 ios swift uitableview

我已经设置了一个 segue,它将显示一个带有小 TableView 的 View Controller 。我想要一个不同的 segue 来显示更大的 TableView,但我希望更大的表具有与较小的表相同的确切信息。让较小的 tableView 自己完美地工作,但是一旦我给较大的表一个数据源,重置并尝试它......崩溃。

//IndexPath 或 TableView 中的第一个单元格

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = UITableViewCell()

    if self.TaskTableViews.hidden == false {
    cell =  tableView.dequeueReusableCellWithIdentifier( "FirstTask" , forIndexPath: indexPath) as UITableViewCell!
    let list = frc.objectAtIndexPath(indexPath) as! List

        cell.textLabel?.text = list.taskName
        cell.textLabel?.textColor = UIColor.whiteColor()
        TaskTableViews.backgroundColor = UIColor.lightGrayColor().colorWithAlphaComponent(0.55)
        TaskTableViews.layer.cornerRadius = 8
        TaskTableViews.separatorColor?.colorWithAlphaComponent(2.0) }

    if self.TaskTable2.hidden == false {
    cell =  tableView.dequeueReusableCellWithIdentifier( "Second Task" , forIndexPath: indexPath) as UITableViewCell!
    let list = frc.objectAtIndexPath(indexPath) as! List
        cell.textLabel?.text = list.taskName
        cell.textLabel?.textColor = UIColor.whiteColor()
        TaskTable2.backgroundColor = UIColor.lightGrayColor().colorWithAlphaComponent(0.55)
        TaskTable2.layer.cornerRadius = 8
        TaskTable2.separatorColor?.colorWithAlphaComponent(2.0) }

        return cell as UITableViewCell

}

最佳答案

问题是您的两个表的代码相互碰撞。要解决此问题,请重新调整您的逻辑。不要让你的逻辑依赖于隐藏的东西。您一次只能处理一张 table ;只有一张 table 在这里打电话。该表作为 tableView 参数出现。让你的逻辑依赖于那个。根据 tableView 参数是什么 TableView ,配置单元格并为该 TableView 返回它。

关于ios - 两个 TableView 一个数据源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35732914/

相关文章:

swift - 确定 Swift 字典是否不包含键并设置默认值

ios - iOS-tableView,按降序对JSON数组排序

ios - 无法将参数传递给 UITableViewCell

ios - 在tableView上方添加一个UIView并在UIView隐藏时开始滚动

ios - 在带有桥头的 Swift 中使用 XLForm

android - Spritefont 文件未加载 Monogame Xamarin

ios - acos和cos的度数未给出正确的结果

ios - 如何防止选择器 View 重复

objective-c - 推送到上一个 View ios 的后退按钮

ios - 表格 View 单元格大小取决于 Storyboard中的预览设备大小