iPhone 视图不显示

发布于 2024-07-27 16:42:12 字数 1653 浏览 2 评论 0原文

我很难显示一个非常简单的视图。 该视图有一个由切换视图控制器管理的自定义视图控制器。 XIB 上有一个 UIViewController 组件,并设置了其 Image 属性。 视图控制器如下:

InstructionsViewController.h

#import <UIKit/UIKit.h>

@interface InstructionsViewController : UIViewController {

}

@end

InstructionsViewController.m

#import "InstructionsViewController.h"

@implementation InstructionsViewController



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

- (void)dealloc {
    [super dealloc];
}


@end

我还将 XIB 文件所有者的类属性设置为InstructionsViewController,并按 Ctrl+拖动文件所有者到“视图”图标,并从弹出菜单中选择“视图”。

显示视图的代码是:

- (void) showInstructions
{
    //Lazy load the instruction view.
    if (self.instructionsViewController == nil)
    {
        InstructionsViewController *viewController = [[InstructionsViewController alloc]
                                                initWithNibName:@"InstructionsView" 
                                                bundle:nil];
        self.instructionsViewController = viewController;
        [viewController release];
    }

    [self.view insertSubview:viewController.view atIndex:0];
}

我的视图控制器在切换不同视图时对它们进行动画处理,加载和显示其他三个视图没有问题。 只是不喜欢这个而已。

我确信我错过了一些简单的事情,但在我的一生中,由于某种原因我无法让它发挥作用。 有人有任何指点吗?

谢谢,

史蒂夫

I am having difficulty geting a very simple view to display. This view has a custom view controller that is manages by a switching view controller. The XIB has one UIViewController component on it with its Image property set. The view controller is as follows:

InstructionsViewController.h

#import <UIKit/UIKit.h>

@interface InstructionsViewController : UIViewController {

}

@end

InstructionsViewController.m

#import "InstructionsViewController.h"

@implementation InstructionsViewController



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

- (void)dealloc {
    [super dealloc];
}


@end

I have also set the class property for the XIB's File's Owner to InstructionsViewController, and Ctrl+Dragged File's Owner to the View icon and selected View from the popup menu.

The code to display the view is:

- (void) showInstructions
{
    //Lazy load the instruction view.
    if (self.instructionsViewController == nil)
    {
        InstructionsViewController *viewController = [[InstructionsViewController alloc]
                                                initWithNibName:@"InstructionsView" 
                                                bundle:nil];
        self.instructionsViewController = viewController;
        [viewController release];
    }

    [self.view insertSubview:viewController.view atIndex:0];
}

My view controller that animates different views when they are switched, has no problems loading and displaying three other views. It just doesn't like this one.

I'm sure I've missed something simple, but for the life of me I can't get it to work for some reason. Does anyone have any pointers?

Thanks,

Steve

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

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

发布评论

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

评论(4

阳光下的泡沫是彩色的 2024-08-03 16:42:12

我刚刚也有同样的事情。 最终删除了 UIImageView,放置了一个新的,然后重新链接,它就工作了。 似乎某个地方有些腐败。

I just had the same thing. Ended up deleting the UIImageView, placing a new one then relinked and it worked. Seems like some corruption somewhere.

顾冷 2024-08-03 16:42:12

甚至不确定这是如何编译的。 您正在将子视图插入到 nil 检查之外,其中 viewController 超出了范围。

您可能想要执行

[self.view insertSubview:self.instructionsViewController.view atIndex:0];

Not even really sure how this is compiling. You are inserting the subview outside of your nil check, where viewController is out of scope.

You probably want to do

[self.view insertSubview:self.instructionsViewController.view atIndex:0];

彻夜缠绵 2024-08-03 16:42:12

您是否通过在此处设置断点来验证是否正在调用 showInstructions ? 另一件需要检查的事情是您正在 z 顺序的底部插入 Instructions 视图,因此它将位于所有其他项目的后面。 尝试使用:

[self.view addSubview:self.instructionsViewController.view];

这会将其添加到 z 顺序的顶部。 如果这不起作用,还可以尝试:

[self.view setNeedsLayout];

和/或:

[self.instructionsViewController.view setNeedsLayout];

Have you verified that showInstructions is being called by setting a breakpoint there? One other thing to check is that you are inserting the Instructions view at the bottom of your z-order, so it will be behind all other items. Try using:

[self.view addSubview:self.instructionsViewController.view];

This will add it to the top of the z-order. If that doesn't work, also try:

[self.view setNeedsLayout];

and/or:

[self.instructionsViewController.view setNeedsLayout];
奢欲 2024-08-03 16:42:12

好吧,我终于解决了!

问题是 XCode 或 Interface Builder 中的某些内容与我为 IB 中的图像视图控件指定的 PNG 文件不一致。 我尝试过重新命名、重新指定等,但无济于事。

我最终不得不删除该图形并从其源位置重新复制它。 然后我在图像视图中重新指定它,构建并运行。 现在可以了。

世界又一切美好了。

感谢那些花时间阅读并提供帮助的人。 我非常感激!

史蒂夫

Ok, I've finally solved it!

The problem was something in XCode or Interface Builder was not agreeing with the PNG file I specified for the Image View control in IB. I tried re-naming, and re-specifying, etc. to no avail.

I finally had to delete the graphic and re-copy it from it's source location. Then I re-specified it in Image View, build and ran. Now it works.

Everything is good in the world again.

Thanks to those who took the time to read and offer help. I appreciate it very much!

Steve

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