Ich bin sehr neu zu swift. Ich habe multiple textfield and button
mit subview
erstellt. Der Ausgang meines ViewController
ist unter: - Wie entferne ich eine Schaltfläche, wenn darauf geklickt wird?
Jetzt muss ich "-"
Taste entfernen, und es entspricht textfield
, wenn es angeklickt wird. Ich kann jedoch nicht feststellen, auf welche Schaltfläche geklickt wurde. Dies ist mein Code:
var y: CGFloat = 190
var by: CGFloat = 192
@IBAction func addRow(sender: AnyObject) {
y += 30
by += 30
let textFiled = UITextField(frame:CGRectMake(50.0, y, 100.0, 20.0))
textFiled.borderStyle = UITextBorderStyle.Line
let dunamicButton = UIButton(frame:CGRectMake(155.0, by, 15.0, 15.0))
dunamicButton.backgroundColor = UIColor.clearColor()
dunamicButton.layer.cornerRadius = 5
dunamicButton.layer.borderWidth = 1
dunamicButton.layer.borderColor = UIColor.blackColor().CGColor
dunamicButton.backgroundColor = .grayColor()
dunamicButton.setTitle("-", forState: .Normal)
dunamicButton.addTarget(self, action: #selector(removeRow), forControlEvents: .TouchUpInside)
self.view.addSubview(textFiled)
self.view.addSubview(dunamicButton)
}
func removeRow(sender: UIButton!) {
print("Button tapped")
self.view.removeFromSuperview()
}
jede Hilfe dankbar ...
probiert mit Tags für Schaltflächen ?? –
können Sie Ihren Code anzeigen –
Ich habe meinen Code hinzugefügt – ripa