簡體   English   中英

工具欄不會顯示在鍵盤上方

[英]Toolbar won't show above keyboard

我不能讓工具欄顯示在上面(就像蘋果有一個完成按鈕)鍵盤。 有什么可以想到為什么它沒有顯示? 如下圖所示。

在此輸入圖像描述

。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;
}

日志

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>>

//使用此方法

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

    textView.inputAccessoryView = yourToolBar;

    return YES;
}

嘗試在viewDidLoad方法中設置它們!

你不能做這個。 鍵盤是一個系統控制的UIView,你無法直接控制。 操作系統將把鍵盤視圖放在所有其他視圖的頂部,以確保它具有正確的焦點來收集用戶輸入。

你能提供更多關於你想要這樣做的背景嗎? 即使您確實找到了一種方法來使視圖按照您的描述行事,但幾乎肯定會被Apple拒絕違反人機界面指南。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM