views:

233

answers:

1

Hi!

I'm learning about AccessoryViews and testing the Apple example: KeyBoardAccessory

I'm trying to show the accessory view avoiding the Keyboard to show, but I can't do it :-(

I'm returning NO in textViewShouldBeginEditing to avoid keyboard and animating the resize of the TextView before return, but nothing happens.

What I'm doing wrong?

- (void)viewWillAppear:(BOOL)animated {

    // Make the keyboard appear when the application launches.
    [super viewWillAppear:animated];
    [textView becomeFirstResponder];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)aTextView {
    NSLog(@"textViewShouldBeginEditing");
    /*
     You can create the accessory view programmatically (in code), in the same nib file as the view controller's main view, or from a separate nib file. This example illustrates the latter; it means the accessory view is loaded lazily -- only if it is required.
     */

    if (textView.inputAccessoryView == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"AccessoryView" owner:self options:nil];
        // Loading the AccessoryView nib file sets the accessoryView outlet.
        textView.inputAccessoryView = accessoryView;    
        // After setting the accessory view for the text view, we no longer need a reference to the accessory view.
        self.accessoryView = nil;
    }

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];

    textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y, textView.frame.size.width, textView.frame.size.height - 100);

    [UIView commitAnimations];    

    return NO;
}
+2  A: 

inputAccessoryView is for a view to come up above the standard apple virtual keyboard. If you don't allow the on-screen keyboard to appear, then the inputAccessoryView will not appear either.

If you ONLY want a custom keyboard to show, and NOT the standard on-screen keyboard, you should use inputView instead of inputAccessoryView. See the difference between inputView and inputAccessoryView here: http://developer.apple.com/iphone/library/documentation/uikit/reference/UITextView_Class/Reference/UITextView.html

annie