ViewController已加载,但视图未显示
我有一个视图,其控制器正在被实例化(NSLog 是这么说的),但该视图没有显示。如果我将它加载为模态视图,它就会出现,但如果我分配它,它就不会出现。
我有这个结构(MenuView是不出现的视图):
// ViewController.h
#import "MenuViewController.h"
@class MenuViewController;
@interface ViewController : UIViewController<ASIHTTPRequestDelegate>{
...
IBOutlet MenuViewController *menuView;
}
...
@property(nonatomic, retain) MenuViewController *menuView;
@end
// ViewController.m
#import "MenuViewController.h"
@implementation ViewController
@synthesize menuView;
- (void)loadMenu{
// THIS WORKS
// [self presentModalViewController:menuView animated:YES];
// THIS DOESN'T (VIEWCONTROLLER IS INSTANTIATED BUT VIEW DOESN'T APPEAR
menuView = [[[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil] autorelease];
[self.navigationController pushViewController:menuView animated:YES];
}
I have a view whose controller is being instantiated (NSLog says so), but the view doesn't show up. If I load it as a modal view it appears, but not if I allocate it.
I have this structure (MenuView is the view that doesn't appear):
// ViewController.h
#import "MenuViewController.h"
@class MenuViewController;
@interface ViewController : UIViewController<ASIHTTPRequestDelegate>{
...
IBOutlet MenuViewController *menuView;
}
...
@property(nonatomic, retain) MenuViewController *menuView;
@end
// ViewController.m
#import "MenuViewController.h"
@implementation ViewController
@synthesize menuView;
- (void)loadMenu{
// THIS WORKS
// [self presentModalViewController:menuView animated:YES];
// THIS DOESN'T (VIEWCONTROLLER IS INSTANTIATED BUT VIEW DOESN'T APPEAR
menuView = [[[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil] autorelease];
[self.navigationController pushViewController:menuView animated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些想法:
尝试在分配时使用 self.menuView:
self.menuView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil];
另外,可能不应该自动释放
属性
。在dealloc
中释放它,并在viewDidUnload
中将其设置为nil
。确保
self (ViewController)
有一个navigationController
。ViewController
是由navigationController
推送/呈现的吗?是否从主线程调用
- (void)loadMenu{
?检查[NSThread mainThread]
查看一些教程/示例:
添加导航手动控制器
NavigationController 应用程序iPhone
教程:介绍 UINavigationController 部分1
iPhone 视图切换教程
Some ideas:
Try using self.menuView when assigning:
self.menuView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil];
Also, probably shouldn't autorelease a
property
. Release it indealloc
and set it tonil
inviewDidUnload
.Make sure that
self (ViewController)
has anavigationController
. WasViewController
pushed/presented by anavigationController
?Is
- (void)loadMenu{
being called from the MainThread? Check with[NSThread mainThread]
Check out some tutorials/examples:
Adding a Navigation Controller by Hand
NavigationController Application in iPhone
Tutorial: Introducing UINavigationController Part 1
iPhone View Switching Tutorial