【发布时间】:2018-02-16 20:00:54
【问题描述】:
我正在使用 UISegmentControl 在表格视图中显示目标类型问题。但是,如果我在任何一个单元格中选择一个段,那么如果我滚动,一些段值会改变。我不知道如何解决。 请指导我。
单元格大小: 160px
分段色调颜色:蓝色
编码
//UIViewController
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = segTblVw.dequeueReusableCellWithIdentifier("segment", forIndexPath: indexPath) as! segmentTblCell
return cell
}
//UITableViewCell CLASS
class segmentTblCell: UITableViewCell {
@IBOutlet weak var segMent: UISegmentedControl!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
截图如下:
【问题讨论】:
-
您能否解释一下您的细分市场在哪里?在表格单元格内?
-
是的.. 在 UITableView 中。 Havin 10 行。
-
我们需要你的一些代码。然而,它看起来像分段控件在单元格内。在这种情况下,当调用 tableView:cellForRowAtIndexPath 并将单元格出列时,必须初始化单元格内的所有组件。由于单元格被重复使用,您最终会得到一些组件显示其他单元格的值,而不是您想要的。
-
我会更新我的完整代码。对不起....
-
我更新了。请帮助我。
标签: swift uitableview uisegmentedcontrol