[英]ViewController is loaded, but the view doesn't show up
我有一个视图,其控制器正在实例化(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];
}
分配时尝试使用self.menuView:
self.menuView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil];
此外,可能不应该自动释放property
。 在dealloc
释放它并在viewDidUnload
中将其设置为nil
。
确保self (ViewController)
有一个navigationController
。 ViewController
是由navigationController
推送/呈现的吗?
是- (void)loadMenu{
是从MainThread调用的吗? 检查[NSThread mainThread]
查看一些教程/示例:
iPhone中的NavigationController应用程序
教程:介绍UINavigationController第1部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.