2013-10-23 2 views
0

내 앱의 스토리 보드는 다음과 같습니다.NSInteger 유형의 변수를 UIPageViewController에 전달

enter image description here

PageViewController의 배열에 정의 된 웹 사이트 목록이 있습니다. 지금 내가하려는 것은 MainViewController의 텍스트 필드에 사용자가 인덱스 번호를 입력하도록하고 페이지 뷰 컨트롤러에서 버튼을 누르면 배열에서 해당 웹 사이트를 표시합니다. 아래 코드는 내 코드입니다. 이 응용 프로그램에 결함이있는 것을 알고있다.이) 그냥 데모입니다

PageViewController.m selectedIndex 속성이 올바르게 번호를 사용자 유형을 얻을 수

#import "MainViewController.h" 
#import "PageViewController.h" 

@interface MainViewController() 

@property (nonatomic, assign) NSInteger selectedIndex; 

@end 

@implementation MainViewController 

- (IBAction)buttonPressed:(id)sender 
{ 
    self.selectedIndex = [self.textField.text integerValue]; 
    [self performSegueWithIdentifier:@"ToNext" sender:nil]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    PageViewController *pageVC = [segue destinationViewController]; 
    pageVC.index = self.selectedIndex; 
} 

@end 

. 문제가 pageVC으로 전달되면 문제가 발생합니다.

이라는 NSInteger 유형의 다른 속성은 PageViewController에 전달되어 값을 검색합니다. 문제는 항상 0을 보여줍니다.

아무에게도 내가 누락 된 내용을 말해 줄 수 있습니까? 나는 정말로 어떤 제안이라도 고맙게 생각한다.

제 질문이 너무 명확하지 않은 경우를 대비하여 내 문제 here을 보여주는 프로젝트를 업로드했습니다.

답변

1
코드 삭제에

:

- (void)awakeFromNib 
{ 
    [super awakeFromNib]; 
    [self createPages]; 
    self.dataSource = self; 

    NSLog(@"Index = %lu", self.index); 
    [self setViewControllers:[NSArray arrayWithObject:self.pages[self.index]] direction:UIPageViewControllerNavigationDirectionForward animated:true completion:nil]; 
} 

에 의해 대체 : 문제를 해결

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    [self createPages]; 
    self.dataSource = self; 

    NSLog(@"Index = %d", self.index); 
    [self setViewControllers:[NSArray arrayWithObject:self.pages[self.index]] direction:UIPageViewControllerNavigationDirectionForward animated:true completion:nil]; 
} 
+0

감사합니다. :) – Isuru

+0

당신을 환영합니다;) –