gpt4 book ai didi

iphone - ViewController 已加载,但 View 未显示

转载 作者:搜寻专家 更新时间:2023-10-30 20:22:16 25 4
gpt4 key购买 nike

我有一个 View ,它的 Controller 正在被实例化(NSLog 是这么说的),但是 View 没有显示出来。如果我将它加载为模态视图,它会出现,但如果我分配它则不会。

我有这样的结构(MenuView是没有出现的 View ):

//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];

另外,可能不应该自动释放一个属性。在dealloc中释放,在viewDidUnload中设置为nil


确保 self (ViewController) 有一个 navigationControllerViewController 是否由 navigationController 推送/呈现?


- (void)loadMenu{ 是否从 MainThread 调用?检查 [NSThread mainThread]


查看一些教程/示例:

Adding a Navigation Controller by Hand

NavigationController Application in iPhone

Tutorial: Introducing UINavigationController Part 1

iPhone View Switching Tutorial


关于iphone - ViewController 已加载,但 View 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7365412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com