ViewController已加载,但视图未显示

发布于 2024-12-04 02:54:47 字数 916 浏览 0 评论 0原文

我有一个视图,其控制器正在被实例化(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁年轻赶紧闹 2024-12-11 02:54:47

一些想法:

尝试在分配时使用 self.menuView:

self.menuView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil];

另外,可能不应该自动释放 属性。在dealloc中释放它,并在viewDidUnload中将其设置为nil


确保 self (ViewController) 有一个 navigationControllerViewController 是由 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 in dealloc and set it to nil in viewDidUnload.


Make sure that self (ViewController) has a navigationController. Was ViewController pushed/presented by a navigationController?


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


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文