InputAccessoryView UITextField - PullRequest
       0

InputAccessoryView UITextField

0 голосов
/ 05 ноября 2011

Мне нужно приклеить панель инструментов с UITextField внутри к клавиатуре.

Что, если я сделаю всю панель инструментов (которую я считаю суперпредставлением textField) представлением inputAccessoryView своего textField?1004 * Я имею в виду так:

textField.inputAccessoryView = toolBar;// textField находится внутри панели инструментов

Я пробовал это, но пока не заставил его работать.

Кто-нибудь может помочь?

Или есть другой способдобиться того, чего я хочу?

Ответы [ 2 ]

2 голосов
/ 19 февраля 2013
   - (void)viewDidLoad
      {
        [self createAccessoryView];

        [textField setDelegate:self];
        [textField setKeyboardType:UIKeyboardTypeDefault];
        [textField setInputAccessoryView:fieldAccessoryView];


      }


- (void)createAccessoryView
        {

            CGRect frame = CGRectMake(0.0, self.view.bounds.size.height, self.view.bounds.size.width, 44.0);
            fieldAccessoryView = [[UIToolbar alloc] initWithFrame:frame];
            fieldAccessoryView.barStyle = UIBarStyleBlackOpaque;
            fieldAccessoryView.tag = 200;

            [fieldAccessoryView setBarStyle:UIBarStyleBlack];

            UIBarButtonItem *spaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
            UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone  target:self action:@selector(done:)];

            UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(@"Previous", @""), NSLocalizedString(@"Next", @""), nil]];
            [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
            segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
            [segmentedControl setMomentary:YES];
            UIBarButtonItem *segmentButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];

            [fieldAccessoryView setItems:[NSArray arrayWithObjects:segmentButton, spaceButton, doneButton, nil] animated:NO];
            [segmentButton release];
            [spaceButton release];
            [doneButton release];
            [segmentedControl release];

        }
0 голосов
/ 07 ноября 2011

Когда вы устанавливаете свойство?Возможно, вы устанавливаете его после того, как представление уже загружено.

Попробуйте установить его в

- (void) viewDidLoad
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...