Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NavigationController未显示在UIViewController上以模式显示_Iphone - Fatal编程技术网

Iphone NavigationController未显示在UIViewController上以模式显示

Iphone NavigationController未显示在UIViewController上以模式显示,iphone,Iphone,有一个mainviewcontroller,上面有一个UIToolbar,其中有一个UIBarButtonim信息,它以模式显示UIViewcontroller #import "ModalViewController.h" #import <QuartzCore/QuartzCore.h> @implementation ModalViewController @synthesize textView; @synthesize navBar; @synthesize navig

有一个mainviewcontroller,上面有一个UIToolbar,其中有一个UIBarButtonim信息,它以模式显示UIViewcontroller

#import "ModalViewController.h"
#import <QuartzCore/QuartzCore.h>

@implementation ModalViewController

@synthesize textView;
@synthesize navBar;
@synthesize navigationController;
@synthesize delegate;

-(void)dealloc
{
  [textView release];
[navBar release];
[navigationController release];
[super dealloc];
 }

- (void) viewDidLoad
{
    [super viewDidLoad];

self.title = @"Info";

UINavigationController *navigationController = [[UINavigationController alloc]init];
                                                 //initWithRootViewController:viewController];

self.navigationController.navigationBar.tintColor = [UIColor brownColor];

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done:)] autorelease];

self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)]autorelease];

self.textView.textColor = [UIColor whiteColor];

self.textView.font = [UIFont fontWithName:@"Georgia-BoldItalic" size:14];

//self.textView.delegate = self;

self.textView.backgroundColor = [UIColor brownColor];

self.textView.layer.borderWidth = 1;

self.textView.layer.borderColor = [[UIColor whiteColor] CGColor];

self.textView.layer.cornerRadius = 1;

self.textView.textAlignment =  UITextAlignmentCenter;

self.textView.text = @"This is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.

self.textView.editable = NO;

 //[self.view addSubview:navigationController.view];

[self.view addSubview: self.textView]; 

//[navigationController release];
现在,当按下Infobutton时,它会以模式显示UIViewController,其中包含UIExtView,但不会显示带有Done按钮的UINavigationController

我无法找出代码中缺少的内容

这就是我如何在UIViewController中显示UITextView和NavigationController的方式

#import "ModalViewController.h"
#import <QuartzCore/QuartzCore.h>

@implementation ModalViewController

@synthesize textView;
@synthesize navBar;
@synthesize navigationController;
@synthesize delegate;

-(void)dealloc
{
  [textView release];
[navBar release];
[navigationController release];
[super dealloc];
 }

- (void) viewDidLoad
{
    [super viewDidLoad];

self.title = @"Info";

UINavigationController *navigationController = [[UINavigationController alloc]init];
                                                 //initWithRootViewController:viewController];

self.navigationController.navigationBar.tintColor = [UIColor brownColor];

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done:)] autorelease];

self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)]autorelease];

self.textView.textColor = [UIColor whiteColor];

self.textView.font = [UIFont fontWithName:@"Georgia-BoldItalic" size:14];

//self.textView.delegate = self;

self.textView.backgroundColor = [UIColor brownColor];

self.textView.layer.borderWidth = 1;

self.textView.layer.borderColor = [[UIColor whiteColor] CGColor];

self.textView.layer.cornerRadius = 1;

self.textView.textAlignment =  UITextAlignmentCenter;

self.textView.text = @"This is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.\nThis is UITextView presenting modally.

self.textView.editable = NO;

 //[self.view addSubview:navigationController.view];

[self.view addSubview: self.textView]; 

//[navigationController release];
如果您能找出我在代码中做错了什么或遗漏了什么,我将不胜感激

非常感谢

@synthesize navigationController;
因此,
navigationController
是您的类成员变量

在函数中

- (void) viewDidLoad
您声明了一个局部变量

UINavigationController *navigationController
请注意,第二个
navigationController
与您的成员变量
navigationController
不同

因此,在
viewDidLoad
中,您需要创建成员变量
navigationController
的对象。不是本地变量
navigationController

不要在
viewDidLoad
中重新声明
navigationController
。而是使用成员变量创建对象,如:

navigationController = [[UINavigationController alloc]init];

这似乎是一种显示新控制器的不必要的复杂方式。在我的应用程序中,我是这样做的:

//此函数显示嵌套在导航控制器中的视图控制器(模式)

- (void) showModalController
{
    YourViewController * ecreator = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];

    UINavigationController * navcontrol = [[UINavigationController alloc] initWithRootViewController: ecreator];

    [self presentModalViewController: navcontrol animated:YES];
    [navcontrol release];
    [ecreator release];
}

现在,您想在YourViewController的initWithNib和/或viewDidLoad功能中进行图形设置(导航栏颜色等)。

试试这个,它对我来说非常有用。我也有同样的问题

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@“segue_name"])
    {
        UINavigationController *nav = [segue destinationViewController];
        ExampleViewController *exampleVC = (ExampleViewController *) nav.topViewController;

        //Setup any properties here and segue
    }
}

你能告诉我如何用代码在ViewEddLoad中创建成员变量的对象吗?我现在没有MAC。然而,它应该像我上面写的那样。不过,您可能需要使用不同的init方法。我正在以编程方式处理它。