ios - 了解 TableView 和 UISegmentedControl

标签 ios swift

我需要一些帮助来了解如何使用 UISegmentedControl 过滤 Uitableview 中的信息。我有一个 UITabeView ,其数据包含两个不同的数据: Rec 和 Dat 。我想在启动应用程序时加载所有数据,并在用户在 UISegmentedControl 中选择时分离 Deb 和 Rec。当我启动应用程序时,我填充 3 个数组 alls、recs 和 dat。我显示全部数组,并希望在用户更改 UisegmentControl 中的选择时更改/过滤数据。你能帮帮我吗?

@IBAction func filtroDebitoCredito(sender: AnyObject) {

        //when All
        if FiltroControlerTable.selectedSegmentIndex == 0 {
           // tableView.reloadData()  ???
        }
        //When Creds
        if FiltroControlerTable.selectedSegmentIndex == 1 {
          //  ???

        }
        //Debs
        if FiltroControlerTable.selectedSegmentIndex == 2 {
           // ??? 
        }

谢谢帮助

最佳答案

其实,你已经在那里了。您的 TableView 显示模型数据。因此,当用户更改分段控件的值时,切换到正确的模型数据集,并完全按照您所说的,告诉表 reloadData()。我要做的是拥有四个数组:modelallrecsdats。比方说,该表始终显示 model。所以分段控件会复制,比方说,recsmodel 并告诉 TableView 重新加载!

关于ios - 了解 TableView 和 UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28101026/

相关文章:

ios - 需要什么以及如何在 Mac OSX 上安装 zucchini 框架?

arrays - 如何将值从一个数组添加到另一个数组?

ios - Swift 中的 UITextField `setText`

ios - 无法将类型 '__NSDictionaryI' (0x16e9900) 的值转换为 'NSArray' (0x16e96f8)

ios - 如何为 GMSMarker 创建边界

ios - 如何在 Realm swift 中使用 LIKE/CONTAINS 查询双值

ios - 带有图像的 UIBarButtonItem 不显示

ios - 分配并初始化 destinationViewController

ios - 如何在 UITableView 中使用多个自定义单元格 (>1)

ios - 需要一些帮助来配置我的项目架构