繁体   English   中英

ViewController已加载,但视图未显示

[英]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部分

iPhone视图切换教程


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM