2017-01-23 2 views
0

내 프로젝트에 https://github.com/intuit/AnimatedFormFieldTableViewCell을 사용하고 싶지만 설정 단계를 둘러 볼 수 없습니다. 지금까지, 나는 폴더에서 파일을 드래그하고 단계를 따라했습니다UITextFieldDelegate 구현

AnimatedFormFieldTableViewCell을 사용하기 위해서는, 당신이해야 할 모든입니다 :

1)는의 ViewController에 AnimatedFormFieldTableViewCell 펜촉 등록을하는에 재사용 식별자를 위해 UITableView를 구현하고있다.

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.tableView.registerCellNib(AnimatedFormFieldTableViewCell) 

    tableView.reloadData() 
} 

2) CellForRowAtIndexPath에서 AnimatedFormFieldTableViewCell로 셀을 축약합니다.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cellIdentifier = "cell" 
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! AnimatedFormFieldTableViewCell 

    return cell 
} 

3) 셀 자체에서 setLabelText를 호출하여 자리 표시 자의 레이블 텍스트를 변경합니다.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cellIdentifier = "cell" 
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! AnimatedFormFieldTableViewCell 

    cell.setLabelText("Enter title") 

    return cell 
} 

주 :

1), 당신은 단지 AnimatedFormFieldTableViewCell의 위임 (직접의 위임을 정의 할 필요가 없습니다를 정의 할 필요가 당신은 여전히 ​​UITextFieldDelegate 당신이 정기적으로의 UITextField에 구현하는 것과 같은 방법을 구현할 수 있습니다 포함 된 UITextField).

2) 포함 된 UITextField에 액세스하려면 단순히 셀의 cellTextField 속성을 호출하면됩니다. 내 응용 프로그램을 실행하는 경우

I don’t get these last two steps. 

, 나는 AnimatedFormFieldTableViewCell 클래스 self.cellTextfield.delegate = selfunexpectedly found nil를 얻을.

무엇이 누락 되었습니까?

You just need to define the AnimatedFormFieldTableViewCell's delegate

당신은 cellTextField보다는 AnimatedFormFieldTableViewCell의 대리자를 설정할 수 있습니다 :

There is no need to directly define the delegate for the embedded UITextField

명령은 다음을 수행하는 것입니다

+0

당신이'cellTextField'에 액세스하는 신속한 버전에 따라 다를 수 있다는 것을 알고? 그 코드도 포함시켜 주시겠습니까? 문서에는 명시 적으로 '임베디드 UITextField에 대한 위임을 직접 정의 할 필요가 없습니다.'라는 메모가 명시되어 있습니다. self.cellTextField.delegate보다는 원하는 delegate에'self.delegate'를 설정해야합니다. –

+0

@MichaelFourre 나는 그것을 얻지 않는다. 나는'cellTextField'에 접근하고 있지 않습니다. 'UITextFieldDelegate'도 구현하지 않습니다. 나는 어떻게해야할지 모르겠다. 'self.cellTextField.delegate'는 에러가 발생합니다. 이것은'AnimatedFormFieldTableViewCell' 클래스에서 구현되었으며 내 클래스에서는 구현되지 않습니다. – waseefakhtar

+0

@MichaelFourre'cellTextField'에 액세스하지 못하는 이유는 아마도 예기치 않게 발견 된 nil 오류가 발생하는 이유 일 것입니다. 그러나 나는 그것을 올바르게 구현하기 위해 단계를 순차적으로 따라 가고 싶다. – waseefakhtar

답변

1
내 코드는 여기

, 나는 어디에 당신이 사무 오류 모르겠지만, 당신이 찾아 내 코드를 확인할 수 있습니다

import UIKit 

class ViewController2: UIViewController, UITableViewDelegate, UITableViewDataSource { 
    @IBOutlet weak var tableView: UITableView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // register a nib like below 
     let nib:UINib = UINib.init(nibName: "AnimatedFormFieldTableViewCell", bundle: nil) 

     self.tableView.register(nib, forCellReuseIdentifier: "AnimatedFormFieldTableViewCell") 

    } 

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

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 

     return 88.0 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCell(withIdentifier: "AnimatedFormFieldTableViewCell", for: indexPath as IndexPath) as! AnimatedFormFieldTableViewCell 

     cell.setLabelText("Enter title") 

     return cell 
    } 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

     tableView.deselectRow(at: indexPath, animated: true) 
    } 

} 

결과 :

enter image description here

그래서, 단계를 확인하십시오. 어디서 잘못되었는지 확인하십시오.

+0

고마워. 나는 잘못된 오류에 대한 잘못된 진술을보고 있었기 때문에 구현 한 모든 단계를 게시했습니다. 그러나 아무도 내가 펜촉을 제대로 등록하지 않았다는 것을 지적했습니다. – waseefakhtar

0

문서는이 노트 님의 대표자 :

self.delegate = yourUITextViewDelegate

보다는 self.cellTextField.delegate = yourUITextViewDelegate (이것은 잘못된 것입니다)

이 문서가

편집을 설명 것입니다 : 영업 이익은 대의원 할당 코드는 자신의 클래스에없는 것을 명확히; 그것은 포드 클래스에 있습니다. 내가이 문제를 해결하고 있다고 생각하지 않기 때문에 나는이 대답을 지우는 것을 고려하고있다.

+0

그리고'AnimatedFormFieldTableViewCell'의 델리게이트를 어떻게 설정합니까? 'viewDidLoad()'에서 어디에서 구현하고 싶습니까? 'yourUITextViewDelegate'는 무엇이 될까요? – waseefakhtar

+0

'cell.delegate = self'를 지정하여'UITableViewController'의'tableView (_ : cellForRowAt :)'메소드에'delegate'을 설정할 수 있습니다. 그런 다음에'UITableViewController'가'UITextViewDelegate' 프로토콜을 채택하는지 다시 한번 확인하고 싶습니다. @waseefakhtar –

+0

지금까지'UITextFieldDelegate'를'UITableViewDataSource'의 확장과 함께 추가했고'cell.delegate = self'를 구현했습니다. 'UITextFieldDelegate'를 추가하지 않으면 'UITextFieldDelegate'타입에 'MyClass'타입의 값을 할당 할 수 없습니다. ' – waseefakhtar

2

안녕 waseefakhtar 코드에 아무 것도 놓치지 마십시오. 유일한 문제는 잘못 입력 한 것입니다. self.cellTextfield.delegate = selfunexpectedly found nil 오류가있는 것입니다.

이 코드를 시도 :

let myNib = UINib.init(nibName: "AnimatedFormFieldTableViewCell", bundle: nil) 
    self.tableView.registerNib(myNib, forCellReuseIdentifier: "cell") 

PS : 단지 registerNib 방법 구문은