0

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

说明ViewController.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 的 File's Owner 的类属性设置为 InstructionsViewController,将 Ctrl+Dragged File's Owner 设置为 View 图标并从弹出菜单中选择 View。

显示视图的代码是:

- (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];
}

我的视图控制器在切换不同视图时为它们设置动画,加载和显示其他三个视图没有问题。它只是不喜欢这个。

我确定我错过了一些简单的东西,但是对于我的生活,由于某种原因我无法让它工作。有没有人有任何指示?

谢谢,

史蒂夫

4

4 回答 4

1

我只是有同样的事情。最终删除了 UIImageView,放置了一个新的,然后重新链接并且它起作用了。好像哪里有腐败。

于 2012-11-11T09:37:07.700 回答
0

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

你可能想做

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

于 2009-07-17T00:55:14.563 回答
0

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

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

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

[self.view setNeedsLayout];

和/或:

[self.instructionsViewController.view setNeedsLayout];
于 2009-07-18T18:38:29.047 回答
0

好的,我终于解决了!

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

我最后不得不删除图形并从它的源位置重新复制它。然后我在 Image View 中重新指定它,构建并运行。现在它起作用了。

世界上一切都好起来了。

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

史蒂夫

于 2009-07-18T20:32:59.440 回答