我有一个视图,其控制器正在实例化(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];
}
答案 0 :(得分:2)
在分配时尝试使用self.menuView:
self.menuView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil];
此外,可能不应该自动释放property
。在dealloc
中将其释放,并在nil
中将其设置为viewDidUnload
。
确保self (ViewController)
有navigationController
。被ViewController
navigationController
是否从MainThread调用- (void)loadMenu{
?查看[NSThread mainThread]
查看一些教程/示例:
Adding a Navigation Controller by Hand
NavigationController Application in iPhone
Tutorial: Introducing UINavigationController Part 1
iPhone View Switching Tutorial