iPhone next UITextField
I have an application with a UITableView
with grouped style. On each of the cells, there is a UILabel
with a description, and a UITextField
for the user to enter data.
We implemented a toolbar on top of the keyboard, with next and prev buttons (similar to what MobileSafari provides when filling forms). In order to give focus to the next field, we resorted to using the tag attribute with consecutive numbers, and we find the开发者_运维百科 subview by tag.
We can't use the responder chain because all the textfields have a different parent view (their UITableViewCell
).
However, when using the iPhone Simulator, the Tab key on the keyboard (and Shift-Tab) work as expected and will move the focus to the next or prev textfield, regardless on where it is in the view hierarchy. After seeing that, we are sure there must be an API that provides us the required functionality, but we could not find it. Any hints?
I'm not sure exactly what functionality you are trying to implement.
However, I suspect it will be of interest to you that you can access the controller from the cells as follows:
UITableView *myTableView = (UITableView *)self.superview;
NSIndexPath *indexPath = [myTableView indexPathForCell: self];
MyTableViewController *myTableViewController = (MyTableViewController *)(myTableView.delegate);
Once you have messaged the controller, it in turn can access whatever cell is desired with cellForRowAtIndexPath.
精彩评论