Question

I have an iPad app (XCode 4.6, ARC, Storyboards) where I want a popover to appear with a UITextField in it when the user taps a UIButton.

The popover appears, the keyboard appears, but nothing appears in the UITextField. What am I missing?

Here is the code:

    //  make the popover
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 450, 500)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0];  //  frame color?
popoverContent.view = popoverView;

//resize the popover view shown in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(450, 500);

//  add the UITextfield to the popover
UITextField *tf = [[UITextField alloc]init];
[tf becomeFirstResponder];
[popoverView addSubview:tf];

//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];

[popoverController presentPopoverFromRect:((UIButton *)oSendFeedback).frame inView:self.view
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Was it helpful?

Solution

The text field should be created with

UITextField *tf = [[UITextField alloc] initWithFrame:...]

to specify the origin and size of the field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top