2014-03-05 69 views
0

我有一個錯誤,但應用程序運行良好,它使用一個UIscroll中的3個視圖控制器的頁面控件。該錯誤讀取「方法定義'changePage:'未找到」< --- @實現PagerViewController \我該如何解決這個問題?如何解決實施錯誤?

源文件可通過谷歌網站按需提供!

#import "PagerViewController.h" 

@interface PagerViewController() 
@property (assign) BOOL pageControlUsed; 
@property (assign) NSUInteger page; 
@property (assign) BOOL rotating; 
- (void)loadScrollViewWithPage:(int)page; 
@end 

@implementation PagerViewController 

@synthesize scrollView; 
@synthesize pageControl; 
@synthesize pageControlUsed = _pageControlUsed; 
@synthesize page = _page; 
@synthesize rotating = _rotating; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    [self.scrollView setPagingEnabled:YES]; 
    [self.scrollView setScrollEnabled:YES]; 
    [self.scrollView setShowsHorizontalScrollIndicator:NO]; 
    [self.scrollView setShowsVerticalScrollIndicator:NO]; 
    [self.scrollView setDelegate:self]; 
} 

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

    for (NSUInteger i =0; i < [self.childViewControllers count]; i++) { 
     [self loadScrollViewWithPage:i]; 
    } 

    self.pageControl.currentPage = 0; 
    _page = 0; 
    [self.pageControl setNumberOfPages:[self.childViewControllers count]]; 

    UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 
    if (viewController.view.superview != nil) { 
     [viewController viewWillAppear:animated]; 
    } 

     self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width *  [self.childViewControllers count], scrollView.frame.size.height); 
    } 


    - (void)loadScrollViewWithPage:(int)page { 
     if (page < 0) 
      return; 
     if (page >= [self.childViewControllers count]) 
      return; 

     // replace the placeholder if necessary 
     UIViewController *controller = [self.childViewControllers objectAtIndex:page]; 
     if (controller == nil) { 
      return; 
     } 

     // add the controller's view to the scroll view 
     if (controller.view.superview == nil) { 
      CGRect frame = self.scrollView.frame; 
      frame.origin.x = frame.size.width * page; 
      frame.origin.y = 0; 
      controller.view.frame = frame; 
       [self.scrollView addSubview:controller.view]; 
      } 
     } 


    // At the begin of scroll dragging, reset the boolean used when scrolls originate from the UIPageControl 
    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 
     _pageControlUsed = NO; 
    } 

    // At the end of scroll animation, reset the boolean used when scrolls originate from the UIPageControl 
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 
    _pageControlUsed = NO; 
    } 

    @end 

的錯誤說法是「法定義「changePage :;找不到」

如何解決這個問題?

+0

請張貼您的PagerViewController.h。 – Undo

回答

1

該錯誤(其實是一個警告,而不是錯誤)是告訴你,這個類的@interface說,類對象應選擇響應changePage:(無論是通過直接定義或繼承/委派),但你的@implementation節該類沒有在任何地方定義該選擇器。

這是一個警告,因爲它不會停止編譯,但可能導致.h文件的某個位置在該類的某個實例上調用函數changePage:。這會讓您的應用程序崩潰,因爲它試圖在某處找到該函數定義,但不能。

解決此警告的方法是在該類的@implementation的某處定義函數changePage: