1

我有一个 iPad 应用程序(XCode 4.6、ARC、Storyboards),当用户点击 UIButton 时,我希望在其中显示一个带有 UITextField 的弹出框。

弹出窗口出现,键盘出现,但 UITextField 中没有出现任何内容。我错过了什么?

这是代码:

    //  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];
4

1 回答 1

1

应该使用创建文本字段

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

指定字段的来源和大小。

于 2013-08-02T20:25:48.453 回答