如何设置 UITabBarController 上另一个视图的对象的 .hidden 属性

发布于 2024-10-16 13:21:22 字数 1231 浏览 1 评论 0原文

亲爱的大家 - 我有一个基于选项卡的应用程序(作为 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 技术交流群。

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

发布评论

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

评论(1

忆梦 2024-10-23 13:21:22

这种情况是只在第一次显示视图选项卡时发生,还是每次都会发生?出口对象可能尚未创建,因此为零。您可以在 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.

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