XCode iPhone:从子 UIScrollView 隐藏父 UIViewController 中的 UIToolbar
我有一个类似于Apple的PageControl示例的项目。我有一个 UIViewController“PhotoViewController”,其中包含 UIScrollView 和 UIToolbar。 UIScrollView 加载另一个 XIB 和 UIViewController“PhotoScrollViewController”。
在 PhotoScrollViewController 中,我有一个显示图像的 UIButton。我在这个按钮上有一个 IBAction,我想单击它来显示/隐藏 PhotoViewController 中的 UIToolbar。
在 PhotoViewController.h 中,我
@interface PhotoViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet UIToolbar *toolBar;
..
}
@property (nonatomic, retain) UIToolbar *toolBar;
在 PhotoScrollViewController 中尝试了一些操作,例如在 PhotoScrollViewController.h 中导入 PhotoViewController.h 并将其添加到界面中,然后尝试通过我的函数访问它,例如:
@implementation PhotoScrollViewController
- (IBAction)toggleMenu {
photoViewController.toolBar.hidden = NO;
}
但这不起作用。我还尝试了removeFromSuperView和self.parentViewController以及其他一些东西。我不知道如何隐藏这个工具栏(我也尝试过阿尔法,但我根本无法访问工具栏)。
我尝试使用 toolBar.hidden = YES 向 PhotoViewController 添加一个函数。如果我从 PhotoViewController 执行该函数,则此方法有效,但如果我从 PhotoScrollViewController 访问它(在 .h 中使用 PhotoViewController *photoViewController),则此方法不起作用:
@implementation PhotoScrollViewController
- (IBAction)toggleMenu {
photoViewController.toolBar.hidden = NO;
[photoViewController toggleTopMenu];
[[PhotoViewController alloc] toggleTopMenu];
}
@implementation PhotoViewController
- (IBAction)toggleTopMenu {
toolBar.hidden = NO;
}
我也尝试将工具栏添加到 PhotoScrollViewController,并且我可以切换它,但我无法弄清楚如何告诉主 UIViewController 关闭 PhotoViewController...所以无论我以哪种方式解决这个问题,我都不知道如何在 UIViewController 之间正确通信..并且我阅读的文档似乎遵循我的尝试。
I have a project similar to Apple's PageControl example. I have a UIViewController "PhotoViewController" which contains a UIScrollView and a UIToolbar. The UIScrollView loads another XIB and UIViewController "PhotoScrollViewController".
In PhotoScrollViewController, I have a UIButton which displays an image. I have an IBAction on this button, and I would like to click on it to show/hide the UIToolbar in PhotoViewController.
In PhotoViewController.h I have
@interface PhotoViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet UIToolbar *toolBar;
..
}
@property (nonatomic, retain) UIToolbar *toolBar;
I have tried a few things in PhotoScrollViewController, such as importing PhotoViewController.h in PhotoScrollViewController.h and adding it to the interface, then attempting to access it through my function like:
@implementation PhotoScrollViewController
- (IBAction)toggleMenu {
photoViewController.toolBar.hidden = NO;
}
But this doesn't work. I've also tried removeFromSuperView, and self.parentViewController, and some other things. I am not sure how to make this toolbar hidden (I've tried alpha as well, I just can't access the toolbar at all).
I tried adding a function to PhotoViewController instead, using toolBar.hidden = YES. This works if I execute the function from PhotoViewController, but it doesn't work if I access it from PhotoScrollViewController (with PhotoViewController *photoViewController in .h):
@implementation PhotoScrollViewController
- (IBAction)toggleMenu {
photoViewController.toolBar.hidden = NO;
[photoViewController toggleTopMenu];
[[PhotoViewController alloc] toggleTopMenu];
}
@implementation PhotoViewController
- (IBAction)toggleTopMenu {
toolBar.hidden = NO;
}
I also tried adding the toolbar to PhotoScrollViewController instead, and I can toggle it, but I can't figure out how to tell the main UIViewController to dismiss PhotoViewController... so whichever way I attack this problem I don't know how to communicate properly between UIViewControllers.. and the documentation I read seems to follow what I've tried.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您的问题似乎是您无法从另一个控制器引用一个控制器。这可以通过多种方式来完成。
1:加载应用程序时在应用程序委托中创建控制器,并公开对它们的引用,例如作为委托的属性。
2:在创建或显示 PhotoScrollViewController 时传递对 PhotoViewController 的引用。你说这不起作用:
如果你的 photoViewController 引用为零,那么这可能不起作用的唯一方法。在哪里/如何设置它?
Basically, your problem seems to be you cannot reference one controller from another. This can be done in various ways.
1: Create your controllers in your application delegate when loading the application, and expose references to them e.g. as properties of the delegate.
2: Pass references to the PhotoViewController when creating or showing the PhotoScrollViewController. You say this doesn't work:
The only way this may not work if if your photoViewController reference is nil. Where/how do you set it?
[photoViewController.navigationController setToolbarHidden:是动画:否];
仅当 photoViewController 被推入 UINavigationController 时它才有效。否则,设置 toolBar.hidden=YES。
[photoViewController.navigationController setToolbarHidden:YES animated:NO];
It works only if photoViewController is pushed into a UINavigationController. Otherwise, set toolBar.hidden=YES.