Click UITableViewCell to set focus in UITextField in iPad - cocoa-touch

I have seen related questions asking how to set focus at startup with firstResponder, but this is a little different.
When I click on a certain UITableViewCell, I want to set the focus in a specific UITextField. Is there a way to set the focus of the UITextField in this manner?
Thanks.

You can override TouchesBegan on your custom TableViewCell to make the UITextField as the first responder

Assuming you have that cell you want then all you need to do.
[yourTextField becomeFirstResponder];
Also remember the setTags:(NSUInteger*) and viewWithTag: Methods to get cell subviews you have placed.

Related

UITableViewCell as subview?

I want to reuse views and code
Is it ok to add a UITableViewCell as a subview to a common view and not in UITableView?
Is it a good idea?
I don't think it's a good idea. UITableViewCell is made to serve as a cell and nothing else. Just like UIButton is made to be a clickable button. But you might think "well the button looks good, shouldn't i reuse it just as a subview?". No, you shouldn't do that. Button is a button, cell is a cell and so on. If you want to reuse your code then you should provide a kind of custom UIView and let it be subview for your cell or anything you want

Suppress UIPickerView from loading - Obj C

I have a UIPickerView that I created programmatically. It shows up when someone presses the UITextField on the screen. The only problem is that if someone presses the UITextField after the UIPickerView has already been populated, more and more PickerViews start layering on top of the previous one.
What is the proper way to suppress populating a UIPickerView if one is already on screen?
There are ofc. multiple ways of doing this, but the most simple would be to just keep a reference to UIPickerView. In other words just store it away in a class variable and check if it's not nil.
You could also set the tag property on the UIPickerView and by querying it's super view check if it is already there. More info on tags: http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instp/UIView/tag
Does that make sense?
You could disable your UITextField once the UIPicker appears, and re-enable it once you have dismissed the picker.

UIPicker with UITextField

I made a research and all posts here are very blury regarding this issue.
I would like to use a UIPicker when pressing on a UITextField.
I would realy appriciate a step by step guide.
I tryd all posts here but every post gives me only a portion of what I need and I can't seem to connect it all together.
This is the last part of my application and i'm going crazy to finish it..
Thank you in advanced!
Gal
There is an inputAccessoryView property that contains a view that will appear instead of a keyboard on the bottom of the screen. Create a UIPicker, adjust its frame, provide values and assign it to the inputAccessoryView property.
UIPicker will appear when user taps on your UITextField.
If you don't need editing, you may use a UILabel instead of the UITextField. Solution is the same. I have a ready-made class if you need.
Here's a way:
http://www.youtube.com/watch?v=t_F1ex5opgA&t=14m10s
-(BOOL)textfieldShouldBeginEditing:(UITextField *)textField
where textField is the name of your text field.
Call your UIPickerView and return NO so that your picker is loaded rather than the keyboard.
The idea is to call an action that opens the UIPicker when the user taps the UITextField. Because the UITextField does not responde to the usual touchUpInside events that UIButtons respond to, I would just overlay a transparent UIButton on top of the UITextField and just in case, make the text field's userInteractionEnabled property NO. Hook the UIButton to responde to touchUpInside and call a method that opens the UIPicker. Another option would be an immediate response to the text field's touch by implementing "textFieldShouldBeginEditing" and immediately resigning the text field.
The next step would be to present the UIPicker - if we are talking about iPad, this would best be done by using a UIPopoverController. On iPhone, maybe consider bringing it up modally. When you create the view controller that holds this UIPicker, be sure to add a delegate property to it so that whatever value that was selected on the picker can be transfered back to the main view controller and on to the UITextField.
Hope this helps with getting you started.

Update a UITextField in a not visible section of UIScrollView without focusing it?

I have to update the text of a UITextField in a not visible section of my UIScrollView but, when I try it, it move the scrollview to it. I don't want this but how can I update my not visible uitextfield without move the scrollview?
Thanks,
Alleria
It is a little unclear what exactly you are trying to do, but I am guessing its either of these, and I am posting them below.
Declare that textField as a property. UITextField *myTextField
If you want to edit that, you can use [myTextField becomeFirstResponder] . This will bring up a keyboard for you to type and enter details, and then you can resignFirstResponder.
If you just want that textField to contain some text, you can just use
self.myTextField.text = #"Some Text";

UITextfield in UITableViewCell resign FirstResnponder

I have a UITextfield of type NumberPad in a UITableViewCell. How can I make it resign first responder (i.e. dismiss the keyboard)?
Thanks
You have to add a UIButton somewhere in your interface. I often do it on the navigation bar and then resign first responder when it is pressed.
There are all sorts of kludges to superimpose fake done buttons over the numberpad, but they are asking for trouble IMHO. It would be nice if Apple addressed this in future though as lots of people have the same issue.
Good discussion and other solutions here;
How to show "Done" button on iPhone number pad
Implement UITextFieldDelegate and set your UITextField delegate to it. In the -(BOOL)textFieldShouldReturn:(UITextField *)textField delegate method you set the resignFirstResponder call.
You can also set up an action to a button on the pad. You can do this by trying to add a done button to the pad. I know that in the most recent sdk this is somewhat impossible.
For those cases you have two options:
1.Add a done button somewhere on the view. If you are using a navigation controller you can add it to the navigation bar and simply set up the action for that button and in the action you resignFirstResponder for the UITextField.
2.Add your keyboard to a UIActionSheet and add the done button right on top of the keyboard.