Toolbar will not appear above the keyboard

I can’t get the toolbar to show above (just like an apple with a pressed button) keyboard. Can anyone think about why it is not displayed? Like the image below.

enter image description here

.h

@interface CustomerNotesController : UITableViewController <UITextViewDelegate>
{
    UIToolbar *noteToolbar;
    IBOutlet UITextView *note;
    id delegate;
}

@property (nonatomic, strong) IBOutlet UITextView *note;
@property (nonatomic, retain) id delegate;
@property (nonatomic, retain) UIToolbar *noteToolbar;

.m

@synthesize note, noteToolbar, delegate;

- (void)viewDidLoad
{
    [super viewDidLoad];

    [note setDelegate:self];
    [note becomeFirstResponder];
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    NSLog(@"EDITING");
    if (noteToolbar == nil) {
        NSLog(@"Creating toolbar");

        noteToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 44.0)];
        noteToolbar.barStyle = UIBarStyleBlackTranslucent;

        UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNote:)];

        UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear" style:UIBarButtonItemStyleBordered target:self action:@selector(clearNote:)];

        UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveNote:)];

        noteToolbar.items = [NSArray arrayWithObjects:cancelButton, clearButton, extraSpace, doneButton, nil];
        NSLog(@"Items: %@", noteToolbar.items);
    }

    NSLog(@"Current field: %@",textView);
    NSLog(@"keyboard: %@", noteToolbar);
    textView.inputAccessoryView = noteToolbar;
}

MAGAZINES

2012-04-11 17:31:00.148 MyApp[28892:fb03] EDITING
2012-04-11 17:31:00.148 MyApp[28892:fb03] Creating toolbar
2012-04-11 17:31:00.149 MyApp[28892:fb03] Items: (
    "<UIBarButtonItem: 0x10dc3420>",
    "<UIBarButtonItem: 0x10dc3480>",
    "<UIBarButtonItem: 0x10dc34e0>",
    "<UIBarButtonItem: 0x10dc3540>"
)
2012-04-11 17:31:00.149 MyApp[28892:fb03] Current field: <UITextView: 0x10d94f40; frame = (5 5; 310 140); text = 'This is sample text'; clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x10d95170>; contentOffset: {0, 0}>
2012-04-11 17:31:00.150 MyApp[28892:fb03] keyboard: <UIToolbar: 0x10dc2820; frame = (0 0; 320 44); opaque = NO; layer = <CALayer: 0x10dc2730>>
+3
source share
3 answers

Try setting them in a method viewDidLoad!

+3
source

// use this method

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{

    textView.inputAccessoryView = yourToolBar;

    return YES;
}
+3
source

. UIView, . , .

Can you give more information on why you would like to do this? even if you figure out how to behave the way you describe, Apple will hardly be rejected for violating the Human Interface Guide.

0
source

All Articles