我有一个动态tableView。 TableViewCell原型是这样的:ios swift在textView单元格中显示/隐藏元素并清除其空间
“------------------”
标签
segmentedControl(是|否)
的TextView
“--- ---------------”
我的问题是如何隐藏,然后显示的TextView是的tableView可以自动调整其细胞高度
这里是我tableViewCell类:
class QuestionTableViewCell: UITableViewCell {
@IBOutlet weak var question: UILabel!
@IBOutlet weak var answer: UISegmentedControl!
@IBOutlet weak var comment: UITextView!
这里是我的tableView cellForRowAtIndex:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("QuestionCell", forIndexPath: indexPath) as! QuestionTableViewCell
cell.question.text = "\(indexPath.row + 1). " + questions[indexPath.row]
// check answer and set it to segmentedControl and set color
if questionsAnswers[indexPath.row] == "YES" {
cell.answer.selectedSegmentIndex = 0
cell.answer.tintColor = UIColor(hex: 0x42DC5A)
} else {
cell.answer.selectedSegmentIndex = 1
cell.answer.tintColor = UIColor(hex: 0xD9393E)
}
if cell.comment != nil {
cell.comment.delegate = self
cell.comment.text = "Add a note if necessary.."
cell.comment.textColor = UIColor.lightGrayColor()
}
if questionsAnswers[indexPath.row] == "YES" {
// here i have to hide cell.comment and its space
} else {
// here i have to show it if its possible
}
// pass indexPath.row to action
cell.answer.tag = indexPath.row
cell.answer.addTarget(self, action: "valueChanged:", forControlEvents: .ValueChanged)
return cell
}
// fires when user taps on segmentedControl
func valueChanged(sender: UISegmentedControl){
// switch segment and update questionsAnswers array
switch sender.selectedSegmentIndex {
case 0:
questionsAnswers[sender.tag] = "YES"
sender.tintColor = UIColor(hex: 0x42DC5A)
case 1:
questionsAnswers[sender.tag] = "NO"
sender.tintColor = UIColor(hex: 0xD9393E)
default:
break
}
}
问题 - 有问题
questionsAnswers的文本数组 - 当我保存从分段控制值的数组
很抱歉,如果我的问题是坏,我'在ios编程中的新手(
为textView创建高度约束,并根据偏好将其设置为零或某个值。 – Sandeep