从超级视图重新加载日期

发布于 2024-12-29 22:29:11 字数 719 浏览 2 评论 0原文

我有两个视图,view1 调用:[self.view addSubview:view2.view]; 然后views2 调用:[self.view removeFromSuperview]; 我想要当 view1 重新出现时,重新加载 view1 中的数据,但我无法调用方法或更新 view1 的属性,因为我无法在 view2 中创建#import "view1.h" (我已经做了一个#import "view2.h" 在 vi​​ew1 中)。

这是我的代码:

View1.h:

-(void)reloadData;

View1.m:

#import « View2.h » ; 
View2 *view2 = [[View2 alloc]init]; 
[self.view addSubview:view2.view]; 

View2.h:

#import « View1.h » 

View2.m:

// I want to call reloadData to reload Data of view1 before removing view2
[self.view removeFromSuperview];

I've got two views, view1 calls : [self.view addSubview:view2.view]; then views2 calls: [self.view removeFromSuperview]; and I want to reload data in view1 when view1 reappear but I can't call a method or update a property of view1 because I can't make an#import "view1.h" in view2 (I've made an #import "view2.h" in view1).

This is my code :

View1.h :

-(void)reloadData;

View1.m :

#import « View2.h » ; 
View2 *view2 = [[View2 alloc]init]; 
[self.view addSubview:view2.view]; 

View2.h :

#import « View1.h » 

View2.m :

// I want to call reloadData to reload Data of view1 before removing view2
[self.view removeFromSuperview];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

破晓 2025-01-05 22:29:11

如果正确地重新组织文件,则可以在 view2 中导入 view1,反之亦然。如果您需要 .h 文件中的任何内容,则只需将 #import "view1.h" 放入 view2.h 中。如果您在实现中只需要这个,您可以愉快地将 #import "view1.h" 移动到 view2.m 文件中,从而解决循环依赖关系。

请注意,在许多情况下,如果只是为了创建类型的实例/参数,您可以跳过 .h 文件中的导入。例如

#import "Another.h"

@interface Onething
@property (strong, nonatomic) Another *an;
@end

可以改为

@class Another;

@interface Onething
@property (strong, nonatomic) Another *an;
@end

This 基本上告诉编译器有一个叫做 Another 的东西,但细节现在并不重要。然后您可以稍后在随附的 .m 文件中#import "Another.h" 并像以前一样工作。

If you reorganize your files properly, you can import view1 in view2 and vice versa. You only need to put the #import "view1.h" in view2.h if you need any content right there in the .h file. If you only need this in your implementation, you can happily move #import "view1.h" in your view2.m file and thus resolve the circular dependency.

Note that in many cases you can skip importing in the .h file if this is only to create instances / paremeters of a type. For example

#import "Another.h"

@interface Onething
@property (strong, nonatomic) Another *an;
@end

can be changed to

@class Another;

@interface Onething
@property (strong, nonatomic) Another *an;
@end

This basically tells the compiler that there is a thing called Another but that the details are not important right now. You can then later #import "Another.h" in the accompanying .m file and work as before.

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