1

I have multiple instances of a custom class that takes inputs from keyboard. You can think of UITextField (but they are not UITextField, they are NSObject). However, they all have a property UIControl *control.

These objects are instantiated and put into an array (orders matter), and they are put on the screen in the same order.

Scenario 1: User tabs on the first object, it becomes the first responder. User taps on another object (from the same class) and that becomes the first responder. No problem.

Scenario 2: User tabs on the first object, it becomes the first responder. User taps on the TAB button of the keyboard (iPad or iPhone or wireless keyboard), I want the next object in the array becomes the next responder. iOS picks randomly [? or with some logic not clear to me] another object which is not in the same order as I want.

Problem: Because these objects are NSObjects, how can I intercept the transition to the next object. I tried using tags or tracking who is the first responder, but the problem is, if user taps on an object out of order, it is fine - I don't want to intercept that. I only want to intercept transition from one object to anther only if it is through tapping on TAB (or Next or Return) button of keyboard.

Any idea? Thanks.

Sierra Alpha
  • 3,707
  • 4
  • 23
  • 36
  • why not make a property in your custom class which points to the next object that it should go to (with a weak reference) then just make that object the first responder automatically when tab/return is pressed, if there is no object (like the last one) nothing will happen cuz it will be a message sent to nil. I think you can even use the interface builder to set this custom properties. (then again, i might not be understanding your problem) – Pochi Nov 21 '12 at 01:41
  • @LuisOscar thanks. that is an option I didn't think about, but still there are obstacles: 1) my biggest problem is I don't get anything when TAB button on keyboard is pressed. How can I get that? iOS route that input somewhere else, not to my object. 2) I rather these object don't know anything about each other -- even with a weak reference. Although if I find out that's the only option, I can overlook that. – Sierra Alpha Nov 21 '12 at 01:50
  • Are you using the interface builder at all? and you said they are not uitextfield but they HAVE to be, or you have to have an uitextfield somewhere around to show the keyboard (perhaps a subclass of them) what exactly did you specified them as? (like ur custom subclass could have an uitextfield in it, then this one is the one becoming the first responder) about the return, ill paste the code as an answer cuz it looks funny here – Pochi Nov 21 '12 at 01:54
  • (by the way, by TAB you actually mean the tab? i have never used a keyboard but doesnt it count as a return in the iOS enviroment?) – Pochi Nov 21 '12 at 01:58

1 Answers1

1

You can set your custom class to have something like this

@interface testClassButtonSub : UIButton

@property (weak,nonatomic) IBOutlet UIButton *nextButton;

@end

Then you can even use the interface builder to set which will be the next responder for when a certain action is taken. (an user presses the return when inside a textfield in your custom class)

For the return you have to declare your viewcontroller as the delegate of the specific textview.

First you set the viewcontroller header like this:

@interface RegisterViewController : UIViewController <UITextFieldDelegate>

then you set the delegates in the implementation

// Set Delegates of the Text Fields
eMail.delegate = self;
userPassword.delegate = self;
userNickname.delegate = self;

and you use this delegate method to jump to the next object

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{    
    // Jumping code here
    return NO;
}

HOWEVER in your case your textfield must be inside your object, so you have to make THAT object the delegate, and in that object's implementation jumping code add the

[thisObjectsTextfield becomeFirstResponder];
Pochi
  • 13,391
  • 3
  • 64
  • 104
  • Thanks for your answer but there is no UITextField. The class conforms to UIKeyInput protocol. I found my answer in - (void)insertText:(NSString *)text required method of UIKeyInput protocol. Now I need to come up with a design to communicate this. – Sierra Alpha Nov 21 '12 at 03:00
  • 1
    try this http://stackoverflow.com/questions/9592593/how-do-i-detect-the-return-key-being-pressed-and-respond-to-it-using-the-uikeyin – Pochi Nov 21 '12 at 03:24