ios 如何在 ipad 中创建 Popover?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6939493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:57:42  来源:igfitidea点击:

How to create Popover in ipad?

ioscocoa-touchipaduipopovercontroller

提问by kernel.roy

I want to develop a popover in my iPad application. A UIButton trigger will call the popover and that popover will contain a UITableViewController.

我想在我的 iPad 应用程序中开发一个弹出窗口。UIButton 触发器将调用弹出窗口,该弹出窗口将包含一个 UITableViewController。

First I need a popover.

首先我需要一个popover。

Need some example code or direction or link.

需要一些示例代码或方向或链接。

Thanks in advance.

提前致谢。

回答by Prerna

in your viewcontroller on the button action write this code:

在按钮操作上的视图控制器中编写以下代码:

- (IBAction)openAllRhymes:(id)sender{
    UIButton *button = (UIButton*)sender;

    PopupTableView *tableViewController = [[PopupTableView alloc] initWithStyle:UITableViewStylePlain];


    popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
    [popover presentPopoverFromRect:CGRectMake(button.frame.size.width / 2, button.frame.size.height / 1, 1, 1) inView:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    [tableViewController release];
}

Now you have created a tableview for popover in that tableviewcontroller write:

现在你已经在那个 tableviewcontroller 中为 popover 创建了一个 tableview 写:

self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(108,400);

回答by omz

Read the documentation, it's all in there. If you don't understand it, start with general tutorialson iOS development or ask specifically about the parts you don't understand. You will need a solid understanding of how view controllers work before it makes sense to work with popovers. The View Controller Programming Guidealso has a section specifically about popovers.

阅读文档,一切都在那里。如果你不明白,从iOS开发的一般教程开始,或者专门询问你不明白的部分。在使用 popovers 之前,您需要对视图控制器的工作方式有深入的了解。该视图控制器编程指南还拥有约popovers明确的部分。

回答by Kasaname

  TAableViewController *tableViewController = [[[TAableViewController alloc] initWithNibName:@"TAableViewController" bundle:[NSBundle mainBundle]] autorelease];
    UINavigationController *nav = [[UINavigationController alloc]
                                   initWithRootViewController:tableViewController];


    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:nav];
    [nav release];
    popover.delegate = self;
    popover.popoverContentSize = CGSizeMake(320, 497);
    [popover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Here in this :-

在这里: -

1) TAbleViewController has the table you want to load . 2) i am adding this to the navigation controller 3) navigation controller to the popover

1) TAbleViewController 有你想要加载的表。2)我将此添加到导航控制器 3)导航控制器到弹出窗口