2013-10-19 2 views
0

네비게이션을 이해하는 데 도움이됩니다. 나는 xibs와 함께 일하고있다. 구성표는 https://www.dropbox.com/s/o82fxpte0hmyxcq/Scheme_Simple.jpg입니다. 다음은 내 코드입니다 :iOS 앱에서 xib로 내비게이션

@implementation AppDelegate 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    FirstViewController *firstViewController = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 
    self.window.rootViewController = navigationController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

@implementation FirstViewController 
- (IBAction)button1Tapped:(id)sender { 
    SecondViewController *secondViewController = [[SecondViewController alloc] init]; 
    secondViewController.title = @"View2"; 
    [self.navigationController pushViewController:secondViewController animated:YES]; 
} 

@implementation SecondViewController 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    ThirdViewController *thirdViewController = [[ThirdViewController alloc] init]; 
    thirdViewController.title = @"View3"; 

    if (indexPath.row == 0) {  
     [self.navigationController pushViewController:thirdViewController animated:YES]; 
     [secondViewTableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 
} 

그래서, 내가 질문 : 나는 다음 뷰를 생성한다

  1. ? 내 코드보기에서 "이전"클래스에서 만든 : view2 FirstViewController, view3 SecondViewController 등 만든 모든 새로운 ViewControllers 내비게이션을 시작하는 메서드 안에 있습니다, 그것은 옳은 방법? 나는 그것이 틀렸다라고 생각한다. 그러나 네비게이션은 일하고있다.

  2. 탐색 모음의 머리글 문제. view2의 제목은 view1에서 view2로 이동할 때만 표시되지만, view3에서 view2로 돌아 가면 - 헤더가 사라집니다. 내가 봤는데, self.title = @"name"viewDidLoad, initWithNibName, viewWillAppear에 추가하려고 시도했습니다.이 중 아무 것도 작동하지 않습니다.

+0

답변 포인트 1. 포인트 2. 여기에 붙여 넣은 코드에서 예상대로 작동해야합니다. 내비게이션 컨트롤러에 내장 된 뒤로 버튼을 사용하고 있습니까? –

+0

예, 사용자 지정 탐색 항목이나 탐색 모음을 사용하지 않습니다. 나머지 코드는 기본적으로 있으며 아무 것도 수행하지 않습니다. 어쩌면 이유는 인터페이스 빌더에 탐색 모음을 생성해야합니다, 콘센트, 속성 등을 만들 수 있습니까? –

+0

원하지 않으면 인터페이스 빌더에서 생성 할 필요가 없습니다. 나는 정말로 당신이 올린 것에 대해 잘못된 것을 발견 할 수 없다. –

답변

0

그래서 탐색 모음의 제목이 사라져서 문제가 해결되었습니다. 내 맞춤 뒤로 버튼에 문제가 있습니다. self.navigationItem.title = @""; 내 뒤로 버튼에서 "뒤로"라는 제목이 사라졌지만 탐색 바의 제목도 사라졌습니다. 뒤로 버튼을 무제한으로 만드는 올바른 방법은 다음과 같습니다.

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil]; 
[self.navigationItem setBackBarButtonItem:backButton]; 
관련 문제