将另一个 NIB 加载到 UIVIEW 的一个子视图中

发布于 2024-12-05 23:36:28 字数 927 浏览 2 评论 0原文

我有一个简单的问题,我在整个网站上看不到它的答案,

一个以 UIView 作为主要内容的 XIB 文件,

其中有另一个连接到一个 IBoutlet 的 UIView,这样我可以稍后分配它来加载视图另一个 XIB 文件。该分配不起作用..它仍然是空白...

@interface Subclass : UIViewController { 
        UIView *view1; 
}
@property (nonatomic,retain) IBOutlet UIView *view1;
@end

我将 view1 链接到 xib 文件中的子视图 在 initWithNibName 的实现中,我正在加载其他 XIB 文件并使用它的视图并将其分配给 view1。但这仍然不起作用...

detailControler = [[XibViewControler alloc] initWithNibName:@"XibViewControler" bundle:nil];
 //one aproach
[self.view1 addSubview: detailControler.view]; 
//another aproach
[self setView1:detailControler.view];

如果我以编程方式将子视图添加到 [self.view addSubview:detailControler.view] 并为其设置一个框架,它将全屏显示,并隐藏原始视图。

我也有不同的方法但不起作用 如何加载多个视图使用 UISegmentedVIew 时点击每个按钮

I have a simple question that I couldn't see it answered on the whole site,

One XIB file that has a UIView as the main,

in it has another UIView that's connected to one IBoutlet so I can assign it later to load a view from another XIB file. That assignment doesn't work.. it remains blank...

@interface Subclass : UIViewController { 
        UIView *view1; 
}
@property (nonatomic,retain) IBOutlet UIView *view1;
@end

i linked view1 to the subview in the xib file
in implementation in initWithNibName I'm loading Other XIB file and use it's view and assigning it to the view1. Still this doesn't work...

detailControler = [[XibViewControler alloc] initWithNibName:@"XibViewControler" bundle:nil];
 //one aproach
[self.view1 addSubview: detailControler.view]; 
//another aproach
[self setView1:detailControler.view];

If I'm adding the subview programaticaly to [self.view addSubview:detailControler.view] and set a frame to it, it will go fullscreen, and hide the original view.

I also had a different approach that didn't work
How to load multiple views on each button tap when using a UISegmentedVIew

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

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

发布评论

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

评论(1

没︽人懂的悲伤 2024-12-12 23:36:28

这就是我通常在另一个视图中设置 UIView 的方式,尽管我不完全确定这是否是最佳实践或类似的做法:

if(newViewController == nil){
  newViewController = [[NewViewController alloc] initWithCoder:nil];
}
newViewController.view.autoresizingMask = UIViewAutoresizingNone;
if([newViewController.view superview] == nil){
  [view1 addSubview:newViewController.view];
}

希望有帮助!

This is how I usually set up a UIView inside another view, although I'm not entirely sure if it's best practice or anything like that:

if(newViewController == nil){
  newViewController = [[NewViewController alloc] initWithCoder:nil];
}
newViewController.view.autoresizingMask = UIViewAutoresizingNone;
if([newViewController.view superview] == nil){
  [view1 addSubview:newViewController.view];
}

Hope that Helps!

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