带有自己的 XIB 的 PopoverView 中的 UIButton 应将操作发送到主视图
Posted
技术标签:
【中文标题】带有自己的 XIB 的 PopoverView 中的 UIButton 应将操作发送到主视图【英文标题】:UIButton in PopoverView with own XIB should send action to mainview 【发布时间】:2011-07-17 11:31:40 【问题描述】:我有一个弹出视图,调用方式为:
Info *infoview = [[Info alloc]init];
pop = [[UIPopoverController alloc]initWithContentViewController:infoview];
[pop setDelegate:self];
[pop presentPopoverFromRect:CGRectMake(-60, 30, 400, 400) inView:bigMenuView permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[infoview release];
在这个 popoverview 中(见代码)一个 info.xib,它有一些 UIBUttons。
现在我想改变一些东西。单击按钮后在我的“主视图”中。
注意:我可以在“First Responder”中访问我的 IBAction 方法,但没有任何操作。
【问题讨论】:
所以您希望infoview
中的按钮向mainView
发送消息?
【参考方案1】:
为了做你想做的事,在Info
的按钮上声明一个属性,类似于:
@property(retain) IBOutlet UIButton *myButton;
现在合成它,在实现部分。为了让按钮向正确的目标发送正确的操作,您应该这样做:
Info *infoview = [[Info alloc]init];
// set the action/target here
[infoView.myButton addTarget:bigMenuView
action:@selector(theSELYouWant)
forControlEvents:UIControlEventTouchUpInside];
pop = [[UIPopoverController alloc] initWithContentViewController:infoview];
[pop setDelegate:self];
[pop presentPopoverFromRect:CGRectMake(-60, 30, 400, 400)
inView:bigMenuView
permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[infoview release];
我以为主视图是bigMenuView
。
这将使按钮在每次被触摸时向bigMenuView
发送theSELYouWant
消息。
【讨论】:
好的,谢谢! @selector 命令将动作发送到我想要的任何地方?第二个代码片段参与我的 info.m?编辑:第二部分参与我的主视图......我猜......@selector
实际上会返回一个SEL
,它是代表selectors的类型。是的,你应该在你指定的目标中编写一个方法-(void)theSELYouWant;
,在你的情况下是主看法。试一试,如果我的答案符合您的需要,请单击复选标记;)
好的...我的主视图不是大菜单视图,这只是在主视图中显示菜单的视图... selectorYouWant 是(button_click :) 它是我的主视图中的 ab IBAction 方法,但是什么也没发生:-/
我可以用“self”在那里选择我的目标吗?
[infoView.myButton addTarget:self action:@selector(button_click:) forControlEvents:UIControlEventTouchUpInside];
以上是关于带有自己的 XIB 的 PopoverView 中的 UIButton 应将操作发送到主视图的主要内容,如果未能解决你的问题,请参考以下文章
如何在popoverview中显示两个按钮-WEPOPOVER