2012-01-20 2 views
1

mainviewcontroller가 있고 UIViewController를 모달로 표시하는 UIBarButtonItem Info가있는 UIToolbar가 있습니다.NavigationController가 모달로 표시하는 UIViewController에 표시되지 않습니다.

Infobutton을 누르면 UIViewController가 모달로 UITextView를 표시하지만 완료 단추가있는 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]; 

}

그리고 이것은 UIViewController에 당신은 내가 잘못 또는 내 코드에서 누락하고있어 알아낼 수 있다면 나는 감사합니다 모달

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

} 

되게하는 방법이다.

고마워요.

답변

1

이것은 새 컨트롤러를 불필요하게 복잡하게 표시하는 것처럼 보입니다. 내 응용 프로그램에서 나는 다음과 같이 그것을 다음에 이제 그래픽 설정을 수행 할

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

navcontroller (등 메뉴 바 색상) 안에 중첩

//이 기능 표시 (모달) 뷰 컨트롤러를 initWithNib 및/또는 viewDidLoadYourViewController의 기능.

+0

프로그래밍 방식으로 처리하고 있습니다. – user1120133

1
@synthesize navigationController; 

따라서 navigationController은 클래스 멤버 변수입니다. 기능

- (void) viewDidLoad 

에서

당신은

UINavigationController *navigationController 

두 번째 navigationController 당신의 멤버 변수 navigationController 다른 것을 알 수하십시오 로컬 변수를 선언합니다.

그래서 viewDidLoad 안에 회원 변수 navigationController의 개체를 만들어야합니다. 로컬 변수 navigationController이 아닙니다.

navigationControllerviewDidLoad에 다시 선언하지 마십시오. 대신 다음과 같은 멤버 변수를 사용하여 객체를 만듭니다.

navigationController = [[UINavigationController alloc]init]; 
+0

당신은 내가 vieweDidLoad에있는 멤버 변수의 객체를 어떻게 만들 수 있는지 보여 주실 수 있습니까? – user1120133

+0

나는 지금 나와 MAC을 가지고 있지 않다. 그러나, 그것은 내가 위에서 쓴 것과 같아야합니다. 다른 init 메소드를 사용해야 할 수도 있습니다. – haberdar

0

이 기능을 사용해보십시오. 나는 똑같은 문제가 있었다.

- (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 
    } 
} 
관련 문제