2017-09-19 33 views
0

我就迅速3.新手我有這樣的情況:我需要在它下面創建的TextView動態也刪除按鈕......所以按鈕添加字段(TextView的)動態再有就是按鈕下方將其刪除..我把那些看法。讓說「placeholderCD」swift 3如何以編程方式添加UITextView,然後在單擊按鈕時將其刪除?

enter image description here

但問題is..how或者我需要把當刪除按鈕點擊什麼行動?因爲我們不能分配動態按鈕的權利?所以像我下面的代碼:

func AddCommentItem(sender:UIButton){ 
    /** CREATE TEXT VIEW **/ 
    let textView: UITextView = UITextView(frame: CGRect(x: 0, y: (newX + 20), width: 311.00, height: 50.00)); 
    textView.textAlignment = NSTextAlignment.justified 
    //textView.backgroundColor = UIColor.lightGray 
    let borderColor = UIColor.lightGray 
    textView.layer.borderColor = borderColor.cgColor 
    textView.layer.borderWidth = 1.0 
    textView.tag = tagname 
    /** CREATE TEXT VIEW **/ 

    /** CREATE REMOVE TEXT VIEW **/ 
    let btnRemove: UIButton = UIButton(frame: CGRect(x: 240, y: (newX + 52), width: 100, height: 50)) 
    //btnRemove.backgroundColor = UIColor.green 
    btnRemove.setTitle("Remove", for: .normal) 
    btnRemove.titleLabel?.font = btnRemove.titleLabel?.font.withSize(10) 
    btnRemove.tag = tagname 

    btnRemove.setTitleColor(UIColor.gray, for: .normal) 
    btnRemove.addTarget(self, action: #selector(btnRemoveComment), for: .touchUpInside) 
    //btnRemove.tag = 1 

    /** CREATE REMOVE TEXT VIEW **/ 

    cell.placeholderCD.addSubview(textView) 
    cell.placeholderCD.addSubview(btnRemove) 
} 

func btnRemoveComment(Sender:UIButton) { 
    /** HOW I REMOVE THE Related text view object with this action **/ 
} 

回答

0

您可以通過標籤去除的TextView

cell.placeholderCD.viewWithTag(yourTag)?.removeFromSuperview() 
+0

哦cool..let我嘗試分鐘...順便說一下標籤纔可以使用整數正確填寫?我可以添加像字符串,使獨特?對不起,我是新的..謝謝你! – user1400140

+0

沒有標籤僅INT,你可以指定你的IndexPath.row每一個文本框,使他們獨特 –

+0

我問,因爲我需要刪除一些元素不只是TextView的上佔位 – user1400140

相關問題