单击UITableViewCell上的一个UITextField时出现意外行为

时间:2016-07-28 20:56:16

标签: swift uitableview uitextfield

我有一个带有4个标签的TabbedView。 在第一个和第二个选项卡(第一个没有滚动,第二个选项卡),当我单击一个UITextField时,ScrollView具有正常的行为。参见下面的GIF:

enter image description here enter image description here

但是在滚动的第三个视图中,当我单击单元格顶部的一个字段时,滚动滚动到单元格的底部,当我单击单元格底部的TextField时,滚动到单元格的顶部: enter image description here

所以,我对任何UIText都没有任何操作(参见下面的控制器):

class TratamentoTableViewCell: UITableViewCell {

@IBOutlet weak var procedimentoTitle: UIView!
@IBOutlet weak var naoRotoSwitch: UISwitch!
@IBOutlet weak var giganteSwitch: UISwitch!
@IBOutlet weak var paralisiaCompleta: UISwitch!
@IBOutlet weak var paralisiaIncompleta: UISwitch!
@IBOutlet weak var efeitoDeMassaSwitch: UISwitch!

@IBOutlet weak var duduGeral: UITextField!

var indexPath : NSIndexPath = NSIndexPath()
var parentTable : UITableViewController = UITableViewController()
@IBOutlet weak var alterarButton: UIButton!

override func awakeFromNib() {
    super.awakeFromNib()

    procedimentoTitle.borderBottom(UIColor(red: 225/255, green: 225/255, blue: 225/255, alpha: 1).CGColor)

    naoRotoSwitch.transform = CGAffineTransformMakeScale(0.75, 0.75)
    giganteSwitch.transform = CGAffineTransformMakeScale(0.75, 0.75)
    efeitoDeMassaSwitch.transform = CGAffineTransformMakeScale(0.75, 0.75)
    paralisiaCompleta.transform = CGAffineTransformMakeScale(0.75, 0.75)
    paralisiaIncompleta.transform = CGAffineTransformMakeScale(0.75, 0.75)

    alterarButton.layer.cornerRadius = 5

    //let recgonizer = UITapGestureRecognizer(target: self, action: #selector(TratamentoTableViewCell.printa) )
    //procedimentoTitle.addGestureRecognizer(recgonizer)

}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}

我已经尝试了

override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 712
}

我试过

override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

TratamentoTableViewController(完整代码)

import UIKit

class TratamentoViewController: UITableViewController {

var tratamento : [AneurismaTratamento] = [
    AneurismaTratamento(),
    AneurismaTratamento(),
    AneurismaTratamento()
]

override func viewDidLoad() {
    super.viewDidLoad()
}

//Code above added as commented (Works but not as i wish), sometimes the keyboard appear over the textfield
override func viewWillAppear(animated: Bool) {

}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return tratamento.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    return self.tableView.dequeueReusableCellWithIdentifier("TratamentoCell")! as! TratamentoTableViewCell

}

0 个答案:

没有答案