2016-08-03 3 views
0

Я хочу создать в swift tableView с 2 клетками прототипа, в одной ячейке у меня есть метка и текстовое поле, в другой ячейке у меня есть кнопка сохранения, @IBOutlet и @IBAction находятся в отделяемый файл UITableViewCell, я хочу что-то написать в текстовом поле, и при нажатии кнопки сохранения, необходимо изменить label.text с textField.text, но у меня проблема, когда я нажимаю кнопку, значение textField равно нулю. Я сейчас быстро, как решить эту проблему? БлагодаряUITableViewCell с кнопкой «Сохранить». textField и метка

+0

почему вы делая это в 2 разных ячейках? есть только 2 клетки? показать код –

ответ

0

Сценарий это рис enter image description here

есть два файла, TableViewController.swift с этим внутри

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 1 
} 

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


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    if indexPath.row == 0 { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cella", forIndexPath: indexPath) as! TableViewCell 
     return cell 
    } 
    let cell = tableView.dequeueReusableCellWithIdentifier("saveCell", forIndexPath: indexPath) as! TableViewCell 
    return cell 
} 

и второй файл с именем TableViewCell.swift

import UIKit 

класса TableViewCell: UITableViewCell {

@IBOutlet weak var textField: UITextField! 
@IBOutlet weak var label: UILabel! 

override func awakeFromNib() { 
    super.awakeFromNib() 
    // Initialization code 
} 

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

    // Configure the view for the selected state 
} 

@IBAction func saveBtn(sender: AnyObject) { 
    self.label.text = textField.text 
} 

}

0

Я решен вопрос с тегом

cell.propertyName.tag = indexPath.row 

и этот делегат

func textField(textField: UITextField, shouldChangeCharactersInRange range:NSRange, replacementString string: String) -> Bool { 
    if textField.tag == 0 { 
     CoreDataController.sharedIstanceCData.matsDataField = "" + textField.text!+string 
    } else { 
     CoreDataController.sharedIstanceCData.commentDataField = "" + textField.text!+string 
    } 
    return true 
} 

это решить мою проблему, Тпх все

Смежные вопросы