0

This is what I am doing to display a UIToolbar in a UITextField's acceccory view.. Unfortunately I am not able to see it for some reason. What am I doing wrong here?

UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneTyping)];

    UIBarButtonItem *item2 =  [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered
                                                              target:self  action:@selector(gotoNextTextfield:)];



    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];


    NSArray *items = [NSArray arrayWithObjects:item2, flexiableItem, item1, nil];
    toolbar.items = items;

    [inputAccView addSubview:toolbar];

    [self.msgTextField setInputAccessoryView:inputAccView];

Update:

if I remove self.msgTextField.delegate = self; then I can see the toolbar.. but why??

4

2 に答える 2

0

交換してみる

[inputAccView addSubview:toolbar];
[self.msgTextField setInputAccessoryView:inputAccView];

[self.msgTextField setInputAccessoryView:toolbar];
于 2013-06-07T10:13:35.670 に答える
0

.h ファイルに追加します<UITextFieldDelegate>

次に、- (void)viewDidLoadこれを試してみると、うまくいきます:

    // Keyboard Tool Bar

    UIToolbar *toolbar = [[UIToolbar alloc] init];
    [toolbar setBarStyle:UIBarStyleBlackTranslucent];
    [toolbar sizeToFit];


    UIBarButtonItem *nextField =[[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextField)];
    UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard)];

    NSArray *itemsArray = [NSArray arrayWithObjects: nextField, flexButton, doneButton, nil];

    [toolbar setItems:itemsArray];

    [self.msgTextField setInputAccessoryView:toolbar];
于 2013-06-07T10:33:36.693 に答える