如何在 iPad 中的表格视图单元格上单击显示弹出窗口

发布于 2024-12-18 16:38:16 字数 743 浏览 5 评论 0原文

我在我的应用程序中使用 TableView,当我单击表格单元格时,我想要一个弹出视图,表格单元格中的所有内容都应该显示在弹出视图中,所以请建议我该怎么做?

我下面有一些示例代码不起作用。所以建议使用代码我希望单元格中的所有内容都显示在弹出视图中。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView *aView = [[UIView alloc] init];
UIPopoverController *popoverController = [[UIPopoverController alloc] 
                                          initWithContentViewController:aView];
popoverController.popoverContentSize = CGSizeMake(320, 416);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[popoverController presentPopoverFromRect:cell.bounds inView:cell.contentView 
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

i am using a TableView in my application where i want a Pop over View when i clicked on a tabel cell, all the content which is in table Cell should display in a pop over view so plz suggest me how to do??

i have some sample code below which is not working..so suggest with code i want all the content in the cell to displayed in the pop over view.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView *aView = [[UIView alloc] init];
UIPopoverController *popoverController = [[UIPopoverController alloc] 
                                          initWithContentViewController:aView];
popoverController.popoverContentSize = CGSizeMake(320, 416);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[popoverController presentPopoverFromRect:cell.bounds inView:cell.contentView 
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长梦不多时 2024-12-25 16:38:16

UIPopoverController< /a> 类参考明确指出

要显示弹出窗口,请创建此类的实例并呈现它
使用适当的方法之一。初始化实例时
这个类,您必须提供提供以下功能的视图控制器
弹出窗口的内容。弹出窗口的大小通常来自
他们呈现的视图控制器

您的 popoverController 应该有一个视图控制器而不是视图。

YourViewController *aViewController = [[YourViewController alloc] initWithNibName:nibName bundle:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] 
                                          initWithContentViewController:aViewController];

然后你就可以展示这个弹出窗口

The UIPopoverController class reference clearly states

To display a popover, create an instance of this class and present it
using one of the appropriate methods. When initializing an instance of
this class, you must provide the view controller that provides the
content for the popover. Popovers normally derive their size from the
view controller they present

Your popoverController should have a view controller and not a view.

YourViewController *aViewController = [[YourViewController alloc] initWithNibName:nibName bundle:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] 
                                          initWithContentViewController:aViewController];

Then you can present this pop over

心如狂蝶 2024-12-25 16:38:16

你的代码没问题,但是
您应该使用 UIViewController 而不是 UIView。

Your code is fine, but
You should have UIViewController instead UIView.

七度光 2024-12-25 16:38:16

你必须传递视图控制器而不是视图

you have to pass the view controller instead of view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文