2016-09-09 10 views
0

uitextフィールドを編集した後、コレクションビューで最初のセルを選択しようとしています。uitextfieldを編集した後、コレクションビューでセルを選択

in function func textFieldDidEndEditing(textField: UITextField) call関数incandescenteCollection.selectItemAtIndexPath(NSIndexPath(forRow: 0 , inSection: 0), animated: true, scrollPosition: UICollectionViewScrollPosition.CenteredHorizontally)ここでincandescenteCollectionはIBOutletからcollectionviewです。 @IBOutlet weak var incandescenteCollection: UICollectionView!

しかし、動作しません。何か案が?

+0

このテキストフィールドはどこにありますか?それは細胞の中にありますか? – Callam

+0

実際の関連コードを投稿した方が読みやすくなります。 – rmaddy

答えて

0

コントローラにUITextFieldDelegateプロトコルがあり、質問の代理人のテキストフィールドがself(コントローラ)に設定されていることを確認してください。

class ViewController: UIViewController, ..., UITextFieldDelegate { 

    // MARK: Outlets 

    @IBOutlet weak var incandescenteCollection: UICollectionView! 
    @IBOutlet weak var textField: UITextField! { 
     didSet { 
      // If the text field is in your cell, 
      // move this line to cellForItemAtIndexPath 
      // as cell.textField.delegate = self 
      textField.delegate = self 
     } 
    } 

    ... 

    // MARK: UITextFieldDelegate 

    func textFieldDidEndEditing(textField: UITextField) { 

     incandescenteCollection.selectItemAtIndexPath(
      NSIndexPath(forRow: 0 , inSection: 0), 
      animated: true, 
      scrollPosition: .CenteredHorizontally 
     ) 
    } 
} 
+0

あなたの助けてくれてありがとうが、私のために働かなかった。 –

関連する問題