Managing Delegate of UITextFields in Custom UITableViewCell

后端 未结 5 1564
长情又很酷
长情又很酷 2021-01-17 13:05

So I have looked around a quite a bit, and nothing on here seems to explain exactly the correct way of doing this. I have 7 UITextFields within a custom UITableViewCell.

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 13:55

    To declare your TableViewController as the delegate include at the end of your @interface in the TableViewController's .h file.

    @interface MyTableViewController : UITableViewController 
    

    Then, connect the text fields by ctrl-dragging each field under the @interface. Each UITextField is connected to its respective property by an IBOutlet. Finally, in the .m file include the following function to show the delegate which field you want to return....

    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        [aTextField resignFirstResponder];
        return YES;
    }
    

提交回复
热议问题