나는 스위프트에 아주 새롭다. subview
을 사용하여 multiple textfield and button
을 생성했습니다. 내 ViewController
의 출력은 다음과 같습니다 : - 버튼을 클릭하면 어떻게 제거하나요?
는 지금은 "-"
버튼을 제거해야하고 그것을 클릭하면 그것은 textfield
해당합니다. 그러나 어떤 버튼을 클릭했는지 감지 할 수 없습니다. 이 내 코드입니다 :
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()
}
어떤 도움을 주시면 감사하겠습니다 ...
버튼에 태그를 사용 해보 았습니까? –
ur 코드를 표시 할 수 있습니까 –
내 코드를 추가했습니다 – ripa