2016-09-28 3 views
0

델리게이트 메서드를 사용하여 테이블 셀에 포함 된 텍스트 필드에서 텍스트 값을 저장하는 방법을 이해하는 데 문제가 있습니다. 나는 텍스트 필드를 포함하는 별도의 .xib 파일을 테이블 셀에 사용하고있다. 아래는 cellForRowAt indexpath를 사용하기위한 코드이지만이 코드가 포함 된 텍스트 파일과 신속한 파일 간의 통신 방법을 잘 모르겠습니다.델리게이트 메서드를 사용하여 사용자 지정 셀 텍스트 필드 저장

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let currentCellDescriptor = getCellDescriptorForIndexPath(indexPath) 
    if currentCellDescriptor["cellIdentifier"] as! String == "idEntranceFee" { 
     func textFieldDidBeginEditing(textField: UITextField!) { 

     } 
    } 

답변

0

이것은이 문제를 처리하는 데 사용하는 코드입니다.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    { 
     tableView.registerNib(UINib(nibName: "PostsCell", bundle: nil), forCellReuseIdentifier: "PostsCell") 
     postsCell = tableView.dequeueReusableCellWithIdentifier("PostsCell") as! PostsCell 
     let song = album.objectAtIndex(indexPath.row) as! NSArray 
     let songName = song[0] as? String 
     postsCell.titleLabel.text = songName 
return postsCell 
    } 

이것은 내 postsCell 파일의 모양입니다.

class PostsCell: UITableViewCell 
{ 
    @IBOutlet weak var titleLabel : UILabel! 
    @IBOutlet weak var bodyLabel : UILabel! 
} 

귀하의 질문은 다소 모호하지만 도움이 될 것입니다. 질문이 있으시면 다시 댓글을 남기십시오.

0

각 UITableViewCell의 경우 ViewController의 각 UITextfield에 대한 대리인을 설정해야합니다.

textField.delegate = self 

그런 다음 ViewContoller에 UITextFieldDelegate를 구현 :

extension YourViewController: UITextFieldDelegate { 
    func textFieldDidBeginEditing(textField: UITextField) { 

    } 
    func tableView(tableView: UITableView, didEndEditingRowAtIndexPath indexPath: NSIndexPath) { 

    } 
}