【问题标题】:How to hide particular section in UITableViewController on change of UISwitch in swift如何在 swift 中更改 UISwitch 时隐藏 UITableViewController 中的特定部分
【发布时间】:2015-02-27 12:54:12
【问题描述】:

我的 UITableView 有 3 个部分 1)Show UISwitch 给用户询问是否要显示图片 2)显示两个文本字段 3)Show ImageView 显示图片

我想隐藏关于 UISwitch 更改的第 3 部分。 三个部分都是静态的。 下面给出了uiswitch的动作

 @IBAction func stateChanged(switchState: UISwitch, tableView: UITableView )
{
    if switchState.on {
        showImageLB.text = "Yes"
        println( "The Switch is On")
    } else {
        showImageLB.text = "No"
        println("The Switch is Off")
    }
}

请帮我解决。 谢谢..

【问题讨论】:

    标签: ios uitableview swift


    【解决方案1】:

    每次翻转 UISwitch 时,您都需要在具有 ImageView 的部分中添加一个新行。

    要添加更多行并隐藏部分,您只需在 tableView 上调用reloadData。 一旦你调用了这个reloadData,你下面的两个函数就会被再次调用。

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    - (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    您现在要做的就是,一旦您的开关被翻转,保存一个布尔值并在您的函数中返回不同的值。

    例如。

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    if(switchState.on)
    {
     return 2; // now you are hiding your last section. 
    }
    else
    {
    return 3; // now you are showing all 3 sections when switch is off.
    }
    }
    

    【讨论】:

    • 感谢 iosDev82 .. 我是否应该为此获得一些参考代码或任何参考链接来执行此操作,因为我是 swift 和 ios 的初学者。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 2019-01-02
    • 1970-01-01
    • 2020-10-04
    相关资源
    最近更新 更多