iPhone 视图不显示
我很难显示一个非常简单的视图。 该视图有一个由切换视图控制器管理的自定义视图控制器。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚也有同样的事情。 最终删除了 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.
甚至不确定这是如何编译的。 您正在将子视图插入到 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];
您是否通过在此处设置断点来验证是否正在调用
showInstructions
? 另一件需要检查的事情是您正在 z 顺序的底部插入Instructions
视图,因此它将位于所有其他项目的后面。 尝试使用:这会将其添加到 z 顺序的顶部。 如果这不起作用,还可以尝试:
和/或:
Have you verified that
showInstructions
is being called by setting a breakpoint there? One other thing to check is that you are inserting theInstructions
view at the bottom of your z-order, so it will be behind all other items. Try using:This will add it to the top of the z-order. If that doesn't work, also try:
and/or:
好吧,我终于解决了!
问题是 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