gpt4 book ai didi

ios - 更改 UISwitch 时如何隐藏部分

转载 作者:可可西里 更新时间:2023-11-01 02:15:40 24 4
gpt4 key购买 nike

这是我的 tableView,我想隐藏“eventdays”部分我该怎么做?

希望你能帮助我。

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

// set data within item list
self.going = ["You can go?","Whos going"]
self.eventdays = ["Monday", "Sunday", "Wednesday"]
self.others = ["Bread", "Butter", "Paneer"]

// set table view delegate and data source
self.myTableView.delegate = self
self.myTableView.dataSource = self
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}



// Mark: - Table view data source and delegate

// set number of sections within table view
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}

// set number for rows for each setion
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return self.going.count
}
if section == 1 {
return self.eventdays.count
}
if section == 2 {
return self.others.count
}

return 0
}

// set header title for each section
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Can Go?"
}
if section == 1 {
return "Days"
}
if section == 2 {
return "Others"
}

return "Default Title"
}

// set cell content for each row
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

// deque reusable cell
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as UITableViewCell
let row = indexPath.row



//Configure the switches for swipe options
let teilnehmenSwitch = UISwitch(frame:CGRectMake(150, 300, 0, 0));
teilnehmenSwitch.on = false

let eventDaySwitch = UISwitch(frame:CGRectMake(150, 300, 0, 0));
eventDaySwitch.on = false




switch(indexPath.section){
case 0:
cell.textLabel?.text = going[row]
if row == 0 {

cell.accessoryView = teilnehmenSwitch

}

case 1:
cell.textLabel?.text = eventdays[row]
cell.accessoryView = eventDaySwitch
case 2:
cell.textLabel?.text = others[row]
default:
cell.textLabel?.text="Others"
}

// return cell
return cell
}

我怎样才能找出哪个开关发生了变化,这样我就可以将数据保存在 DataBase 中。

提前致谢

最佳答案

您可以通过以下代码更改开关操作以获得更优化的重新加载解决方案

@IBAction func switchValueChange(sender: UISwitch) {
//tableView.reloadData()
tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .None)
}

关于ios - 更改 UISwitch 时如何隐藏部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38786456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com