views:

194

answers:

0

Now we have a UIButton styled as a combo button and custom methods to show a UIPickerView like the keyboard does. In our views with editable controls we detect if we are editing an UITextField or a combo button and then shows the usual keyboard or the picker in our custom way.

But since iOS 3.2 UITextField has the inputView property and it can show an input view different than the usual UIKeyboard.

I'm implementing this approach to simplify things (animation of the picker, centralization of the events in the UITextFieldDelegate methods, etc).

I'm very close to the final implementation but I have a problem: can I hide the cursor? I don't want to not allow editing and track touches because then I will have the same behaviour than with the UIButton. I want to delegate all the event handling to the UITextFieldDelegate and don't implement actions on touch events.

Thank you!

EDIT: I think I have the correct solution but If it can be improved will be welcome :) Well, I made a subclass of UITextField and overriden the method that returns the CGRect for the bounds

-(CGRect)textRectForBounds:(CGRect)bounds {
    return CGRectZero;
}

The problem? The text doesn't show because the rect is zero. But I added an UILabel as a subview of the control and overridden the setText method so, as we enter a text as usual, the text field text is nil and is the label which shows the text

- (void)setText:(NSString *)aText {
    [super setText:nil];

    if (aText == nil) {
        textLabel_.text = nil;
    }

    if (![aText isEqualToString:@""]) {
        textLabel_.text = aText;
    }
}

With this the thing works as expected. Have you know any way to improve it?

EDIT 2 I found another solution: subclass UIButton and override these methods

- (UIView *)inputView {
    return inputView_;
}

- (void)setInputView:(UIView *)anInputView {
    if (inputView_ != anInputView) {
        [inputView_ release];
        inputView_ = [anInputView retain];
    }
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

Now the button, as a UIResponder, have a similar behavior than UITexxField and an implementation pretty straightforward.