views:

79

answers:

1

Hello guys!

I have an iPad project. In the project I have a toolbar and then I add a textfield on it. Here's my simplified code.

- (void)viewDidLoad {
  [super viewDidLoad];
  UITextField *pageNumbersView = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
  pageNumbersView.clearsOnBeginEditing = YES;
  pageNumbersView.borderStyle = UITextBorderStyleRoundedRect;
  pageNumbersView.textAlignment = UITextAlignmentCenter;
  pageNumbersView.userInteractionEnabled = YES;
  pageNumbersView.keyboardType = UIKeyboardTypeNumberPad;
  pageNumbersView.returnKeyType = UIReturnKeyDone;
  UIBarButtonItem *pagesIndicator = [[UIBarButtonItem alloc] initWithCustomView:pageNumbersView];
  UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 100, 768, 44)];
  toolbar.items = [NSArray arrayWithObject:pagesIndicator];
  [self.view addSubview:toolbar];
}

When I click the textfield the keyboard appears. Now the problem is that on the keyboard I press the rightmost button on the bottom of the keyboard (Keyboard hide button?) and nothing happens. If I add my textfield to the view not to the toolbar it is working. Any idea about the problem? How can I solve it? Thanks for the answers.

A: 

Try using the Interface Builder to add a textfield instead of hardcoding it.

mcandre
In this case I need hardcoding, because I would like to use the navigationcontroller's toolbar and from intetfacebuilder I can't do this if the navigationcontroller is created from code. I wouldn't like to change my whole logic.
Infinity
Can InterfaceBuilder insert a textfield inside the toolbar? If it can, then don't hardcode the toolbar either. Use InterfaceBuilder for that, too.
mcandre