2016-02-15 2 views
-1

У меня есть UITableView, с обычаем UITableViewCell имеет два uitextfiled я хочу, чтобы получить текст каждого uitextfiled как массив есть также кнопка, чтобы добавить новую ячейку в UITableViewмульти uitextfiled в UITableViewCell с Swift

enter image description here

показать, как я могу иметь дело с этим Edit это пользовательский класс uitabelcell

@IBOutlet weak var treatmentCount: UITextField! 
@IBOutlet weak var treatmentText: UITextField! 
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 
} 

и этот UITabelView контроллеру

var tretments = [(name:String,count:String)](count: 15 , repeatedValue: (name: "" , count: "")) 
var tretmentNames = "" 
var tretmnetCounts = NSMutableDictionary() 
var count = 5 
@IBOutlet weak var orderTableView: UITableView! 

@IBAction func addItem(sender: AnyObject) { 
    count += 1 
    save() 
    orderTableView.reloadData() 



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

    // Do any additional setup after loading the view. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = orderTableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! OrderItemTableViewCell 
    cell.treatmentText.text = tretments[indexPath.row].name 
    cell.treatmentCount.text = tretments[indexPath.row].count 

    return cell 


} 
func save() { 
    for rowIndex in 0...self.orderTableView.numberOfRowsInSection(0) { 
     let indexPath : NSIndexPath = NSIndexPath(forItem: rowIndex, inSection: 0); 
     if (self.orderTableView.cellForRowAtIndexPath(indexPath) != nil) { 
      let cell = self.orderTableView.cellForRowAtIndexPath(indexPath) as! OrderItemTableViewCell 
      print(indexPath.row) 
      tretments.insert((name: cell.treatmentText.text!, count: cell.treatmentCount.text!),atIndex:indexPath.row) 
      print("Name:\(cell.treatmentText.text), Count: \(cell.treatmentCount.text)") 
     } 
    } 


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

мне нужно получить весь пользовательский ввод в текстовом поле, а также пропустить другими, что пользователь не ввести любой текста в текстовом поле проблемы здесь в моем коде, когда пользователь пытается прокрутить на uitabelview

+0

Ваш вопрос слишком широк. Вы должны показать код, который вы попытались, и конкретные проблемы, которые у вас есть. – Paulw11

+0

i edit my question –

ответ

0

Вы можете сделать выходную коллекцию и перебрать ее, чтобы получить каждое значение текстового поля. Если вы хотите сохранить заказ, используйте свойство tag.

+0

Я уже пробовал это, но проблема, когда пользователь прокручивает данные, удаленные в текстовом поле –

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