두 가지 방법을 사용할 수 있습니다. 귀하의 질문에서
- UINavigationController가
- 대표
을 UINavigationController가이 최선의 선택 것 같다하지만 난 당신이 모두 표시됩니다.
UINavigationController가
당신이 그렇게 같은 탐색 컨트롤러에 포장해야 할 것 앱 위임에서 mainViewController를로드 :
@property (strong, nonatomic) UINavigationController *navController;
AppDelegate.h을
AppDelegate.m
didFinishLaunchingWithOptions에서
@synthesize navController = _navController;
//은 :
UIViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
navController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
self.window.rootViewController = nav1;
[self.window makeKeyAndVisible];
이제 MainViewController에 당신은이 UINavigationController가의 설득있다. 간단하게 할
ChildViewController *child = [[ChildViewController alloc]...];
[self.navigationController pushViewController:child animated:YES];
당신이 만약 당신의 ChildViewController에 다시 가고 싶어 : 당신이 부모로부터 아이를 밀어하려는 경우
당신은 간단하게 할 수있는
[self.navigationController popViewControllerAnimated:YES];
이가이다 "드릴 다운"기법.
는 (나는 "드릴 다운"단순히를보다 더 의미가 알고 있지만, 기준의 좋은 프레임을 제공합니다.)
위임을
지금 다른 방법 당신이 그 클래스 사이에 대리자를 설치하는 것입니다. 그래서 childView에 있고 부모에게 전화해야 할 경우, 그렇게 할 채널이 있습니다. 지금처럼 MainViewController.h 설정 그것에서
: 당신의 MainViewController.m에서
#import <UIKit/UIKit.h>
//This is our delegate
@protocol TalkToParentDelegate <NSObject>
//This is our delegate method
- (void)helloParent;
@end
@interface MainViewController : UIViewController <TalkToParentDelegate>
...
..
@end
확실히 대리자 메서드를 추가합니다. 당신의 ChildViewController.h 설정에서
- (void)helloParent {
NSLog(@"Hello child, let me do something here");
}
그것과 같이 :
#import <UIKit/UIKit.h>
//Add header of class where protocol was defined
#import "MainViewController.h"
@interface ChildViewController : UIViewController
//Create a property we can set to reference back to our parent
@property (strong, nonatomic) id <TalkToParentDelegate> delegate;
@end
지금, 당신의 MainViewController.m에, 당신이 제시 할 때마다 ChildViewController이 작업을 수행 :
ChildViewController *child = [[ChildViewController alloc]...];
//Set the delegate reference to parent
child.delegate = self;
//present the view
마지막으로 적어도 다음과 같이 부모 (MainViewController)의 메소드를 호출 할 수 있습니다.
[self.delegate helloParent];
그래서 다음 두 가지 방법을 사용할 수 있습니다.
그러나 나는 이것을 함께 사용할 수 있습니다. UINavigationController가 있지만 부모와 대화하기 위해 자식이 필요하다고 가정하면 가능하면 대리자를 설정할 수 있습니다.
7 개의보기를 표시하려면 'UINavigationController' 또는'UIPageViewController '를보십시오. 아마도 도움이 될 것입니다. – matsr
표시하는 데이터를 제외하고 각각 7 개의보기가 동일합니까? 이 데이터, 텍스트보기, 웹보기 등을 표시하기 위해 어떤 객체를 사용하고 있습니까? 또한 모든보기간에 앞뒤로 이동하거나 기본보기에서 다른보기로 이동 한 다음 다시 기본보기로 돌아가고 싶습니까? – rdelmar
아직 구조를 결정하지 않았습니다. 데모 프로젝트이기 때문에 이동 중에도 배우고 구현하고 싶습니다. 주로 사용자는보기간에 이동하거나 앞뒤로 이동해야합니다. 나는 matsr이 제안한대로'UINavigationController'로 작업하기 시작했습니다. – Sobiaholic