综合技术

NavigationController is not displayed on UIViewController showing modally

微信扫一扫,分享到朋友圈

NavigationController is not displayed on UIViewController showing modally
0

Have a mainviewcontroller and on it have UIToolbar which has a UIBarButtonItem Info which shows UIViewcontroller modally.

Now when pressing Infobutton it is showing UIViewController modally which has UITextView but not showing UINavigationController with Done button.

I am not able to figure it out what i am missing in my code.

This is how i am showing UITextView and NavigationController in UIViewController modally.

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

}

And this is how UIViewController presented modally

//Create a final modal view controller

    UIButton *modalViewButton = [UIButton buttonWithType:UIButtonTypeInfoLight];

    [modalViewButton addTarget:self action:@selector(modalViewAction:) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:modalViewButton]; 

   self.navigationItem.rightBarButtonItem = modalBarButtonItem;

- (void) modalViewAction:(id)sender

{
    self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];  

 //self.viewController = [[ModalViewController alloc] init];

 [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

 //ModalViewController *myModalViewController = [[ModalViewController alloc] init];

  //UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myModalViewController];

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

    _viewController = [[ModalViewController alloc] init];

   //[navigationController pushViewController:_viewController animated:YES];

  [self presentModalViewController:self.viewController animated:YES];

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

    //[navigationController release];

    [myModalViewController release];

}

I will appreciate if you can figure out what i m doing wrong or missing in my code.

Thanks a lot.

This seems like a needlessly convoluted way of displaying the new controller. In my apps, I do it like this:

//this function displays (modally) view controller nested inside a navcontroller

- (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];
}

Now you want to do the graphical setup (navbar color etc) in the initWithNib
and/or viewDidLoad
functions of the YourViewController
.

阅读原文...


Hello, buddy!

卡巴斯基报告:70%的黑客攻击事件瞄准Office漏洞

上一篇

Setup Express with TypeScript in 3 Easy Steps

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
NavigationController is not displayed on UIViewController showing modally

长按储存图像,分享给朋友