4

我想在我的iPad应用程序的弹窗视图中显示自定义的tableview。这工作正常。我想在工具栏上添加按钮(在tableview的底部)。工具栏显示为空。任何建议?UIToolbar项目不在弹出窗口中显示

请注意,当用户触摸主视图控制器中的按钮时,会触发以下代码。

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.customTableViewController]; 
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"item 1" style:UIBarButtonItemStylePlain target:nil action:nil]; 
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"item 2" style:UIBarButtonItemStylePlain target:nil action:nil]; 

[navigationController setToolbarHidden:NO]; 
navigationController.navigationBar.topItem.title = @"Some Title"; 

NSArray *array = [[NSArray alloc] initWithObjects:item1, item2, nil]; 
[navigationController setToolbarItems:array]; 

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController]; 
self.popoverController = popover; 
popoverController.delegate = self; 

[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
+1

我打一个类似的问题,实现代码如下所示罚款的酥料饼的,但下面的按钮是不可见的。如果我想出点什么,我会告诉你。 – 2012-05-23 22:04:39

+0

我希望有人解决这个问题。 – Hamdi 2012-05-24 00:53:59

回答

3

我遇到了类似的问题,tableview在弹出窗口中显示正常,但下面的按钮不可见。如果我想出点什么,我会告诉你。

编辑:我的问题是,我正在重新调整popover的大小,并且按钮被推出视图。我通过更改自动调整来锁定相对于框架底部的位置来解决此问题。为此,请在界面构建器中查看您的xib,转到右上角的标尺选项卡并使用Autosizing GUI。对于我而言,这意味着在GUI上只选择了底部锚点。

2

在ipad应用程序中,您必须将工具栏项目设置为“topViewController”(是的,这是违反直觉的)。

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:catView]; 
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"item 1" style:UIBarButtonItemStylePlain target:nil action:nil]; 
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"item 2" style:UIBarButtonItemStylePlain target:nil action:nil]; 
[nav setToolbarHidden:NO animated:YES]; 
// WRONG: [nav setToolbarItems:[NSArray arrayWithObjects:addButton, nil]]; 
// CORRECT (for ipad apps): 
[nav.topViewController setToolbarItems:[NSArray arrayWithObjects:item1, item2, nil] animated:NO]; 
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:nav]; 

参见: http://www.kevatron.co.uk/tag/uipopovercontroller/

+0

我遇到了上述相同的问题,除此之外,我尝试了一切。很棒的发现,谢谢! – 2014-06-30 20:21:02