如何设置 UITabBarController 上另一个视图的对象的 .hidden 属性
亲爱的大家 - 我有一个基于选项卡的应用程序(作为 XCode 示例应用程序启动)。
一个选项卡用于选择图像(UIImagePickerController) - 按预期工作。 另一个选项卡用于在包含所选图像的 UIImageView 上显示 CoreGraphics。这是在自定义 UIView 的 drawRect: 方法中完成的。
当选择新图像时,我需要重置 UIView 上的界面。
目前,我的 UIView 中有一个 -(IBAction)resetAll:(id)sender
方法 - 当从同一视图上的按钮调用该方法时,所有内容都会按预期重置。
但是,当我从 ViewController.m 文件的 viewWillAppear 方法调用resetAll方法时:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
TabBarEgAppAppDelegate *delegate = (TabBarEgAppAppDelegate *)[[UIApplication sharedApplication] delegate];
if(delegate.newphotopicked){
[myView resetAll:nil];
delegate.newphotopicked = NO;
}
resetAll方法中的NSLog被触发,但参数(例如button.hidden = YES;
)没有得到放。
这是因为 UIView 被 TabBarViewController 以某种方式隐藏了吗?当选项卡更改时,我还能如何重置视图(UIView 不会调用 viewWillAppear 吗?)。非常感谢您给我时间!
M@
只是澄清一下,ViewController 在 .h 中具有以下内容:
MyView *myView;
在 .m 中
- (void)viewDidLoad {
myView = [[MyView alloc] initWithFrame:CGRectZero];
[myView resetAll:nil];
调用与按钮和应用程序中任何位置的调用具有相同的效果,包括UIView (MyView) 本身。
我现在知道我已经错误地链接或子类化了(请帮助)。
米@
Dear all - I have a Tab Based Application (started as the XCode Example app).
One tab is used to pick an image (UIImagePickerController) - works as intended.
Another tab is used to display CoreGraphics over a UIImageView containing the image chosen. This is done in the drawRect: Method of a custom UIView.
I need to reset the interface on the UIView when a new image is selected.
At present I have a -(IBAction)resetAll:(id)sender
method in my UIView - when this is called from a button on the same view everything resets as intended.
HOWEVER, when I call the resetAll method from the viewWillAppear method of the ViewController.m file:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
TabBarEgAppAppDelegate *delegate = (TabBarEgAppAppDelegate *)[[UIApplication sharedApplication] delegate];
if(delegate.newphotopicked){
[myView resetAll:nil];
delegate.newphotopicked = NO;
}
The NSLog in the resetAll method is triggered but the parameters (such as button.hidden = YES;
) do not get set.
Is this because the UIView is hidden in some way by the TabBarViewController? How else can I reset my view when the tab changes (UIView doesn't call viewWillAppear does it?). Thank you so much for giving me your time!
M@
Just to clarify, the ViewController has the following in the .h:
MyView *myView;
in the .m
- (void)viewDidLoad {
myView = [[MyView alloc] initWithFrame:CGRectZero];
The [myView resetAll:nil];
call has the same effect from buttons and calls anywhere in the app INCLUDING on the UIView (MyView) itself.
I know now that I have linked up or subclassed badly (please help).
M@
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种情况是只在第一次显示视图选项卡时发生,还是每次都会发生?出口对象可能尚未创建,因此为零。您可以在 NSLog 调用所在的调试器中验证这一点。如果这是真的,那么如果您将 resetAll 函数移至 viewDidAppear ,那么一切都应该正常。
Does this only happen the very first time the view tab is shown, or every time? It's possible that the outlet objects have not yet been created and so are nil. You can verify this in the debugger where your NSLog call is. If that is true, then if you move your resetAll function to
viewDidAppear
then everything should work.