【问题标题】:Filter tableView rows doesn't reload tableView过滤 tableView 行不会重新加载 tableView
【发布时间】:2016-08-03 06:44:51
【问题描述】:

我的第一个 iOS 应用程序使用简单的自定义单元格,但过滤 tableView 行的增强会导致延迟和挫败感。在线搜索有关过滤行的帮助,阅读 Apple 开发人员指南中的数据源和委托协议,目前没有运气。

使用滑块值刷新表格行。从线阵列(100 项)中提取数据到linefilter 阵列(20)。然后想刷新/重新加载tableview。

Slider 用 0 声明,所有线阵列项目都显示出来。移动滑块不会改变显示。如果滑块声明为 1,则显示 20 个过滤器项。

对 Apple/Xcode/Swift 很陌生,所以没有 Objective C 知识。

任何答案都可能帮助我到达那里。 吉姆 L

相关代码选择:

 @IBAction func moveSlider(sender: AnyObject) {
      // Non-continuous  ******
        _ = false
      // integer 0 to 5  ******
        let slider = Int(lineSlider.value)
        }
    }

 // Global Variable   ******
 var slider = 0

 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        if slider == 0  {        
            return self.line.count
        } else  {  
           return self.linefilter.count
        }
    }

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {        
        let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! myTableViewCell
        if slider == 0  {
            cell.myCellLabel.text = line[indexPath.row]
        } else {
            cell.myCellLabel.text = linefilter[indexPath.row]
        }
        cell.myImageView.image = UIImage(named: img[indexPath.row])
        return cell          
    }
    tableView.reloadata()

【问题讨论】:

    标签: ios swift filter tableview


    【解决方案1】:

    试着放

    tableView.reloadData() 
    

    喜欢这个

    let slider = Int(lineSlider.value)
         tableView.reloadData()
    }
    

    在你的 moveSlider 函数中

    【讨论】:

    • 嗨,谢谢,但运气不好,我也尝试在几个地方重新加载。
    • 我没有看到您的过滤代码,在调用 reloadData() 之后,您是否检查代码是否转到 cell.myCellLabel.text = linefilter[indexPath.row] 或 cell.myCellLabel.text = line[ indexPath.row]?
    • 发现一个问题,在if-else代码中,slider改变值时slider值不更新,它保持初始值0。在moveSlider动作中调用了过滤器代码,但是代码太多会隐藏故障。
    • 您好感谢您的帮助。它现在正在工作并根据需要重新加载 tableview。吉姆。
    • 很高兴听到这个消息,祝你有美好的一天:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多