2013-02-15 81 views
3

在我的iPad應用程序。我正在研究UIPageViewController我想在一個頁面上設置文本,在另一個頁面上設置圖像。我嘗試了很多並使用Google搜索,但我沒有找到任何解決方案。這是在浪費我的時間,所以如果有任何人在工作,請指導我併發布示例代碼。如何在UIPageViewController的另一個頁面設置文本和圖像

我已經使用其中有在下面鏈路

http://www.ioslearner.com/implementing-uipageviewcontroller-programatically-without-storyboarding/

這裏是示例代碼的代碼。我用contentviewcontroller。

我想如果我深知然後加入ContentPageView.xib文件中的ImageView,使的出口使用兩個視圖控制器與UIPageViewController

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController 
       spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation 

{ 

if(UIInterfaceOrientationIsPortrait(orientation)) 

{ 
    //Set the array with only 1 view controller 
    UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0]; 
    NSArray *viewControllers = [NSArray arrayWithObject:currentViewController]; 
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL]; 

    //Important- Set the doubleSided property to NO. 
    self.pageViewController.doubleSided = NO; 
    //Return the spine location 
    return UIPageViewControllerSpineLocationMin; 

} 
else 
{ 
    NSArray *viewControllers = nil; 
    ContentViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0]; 

    NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)currentViewController labelContents]]; 

    NSUInteger currentIndex2 = [self.imagesArray2 indexOfObject:[(ContentViewController *)currentViewController imageContents]]; 

    if(currentIndex == 0 || currentIndex %2 == 0 || currentIndex2 == 0||currentIndex2 %2 == 0) 
    { 
     UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController]; 
     viewControllers = [NSArray arrayWithObjects:currentViewController, nextViewController, nil]; 
    } 
    else 
    { 
     UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController]; 
     viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil]; 
    } 
    //Now, set the viewControllers property of UIPageViewController 
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL]; 

    return UIPageViewControllerSpineLocationMid; 
} 

}

+0

請發表您已經到目前爲止已經試過代碼。 ... – Mohammad 2013-02-15 09:47:33

+0

你如何設置文字和圖像? – fibnochi 2013-02-15 09:50:46

+0

我已經用我在代碼中使用的鏈接編輯了這個問題。請通過它。 – Goutham 2013-02-15 09:54:59

回答

0

按照以下幾個步驟可以幫助

  1. 保持的UILabel和和的UIImageView在ContentViewController
  2. 添加的UIImage OR的NSString在modelArray。
  3. 當您製作新的ContantViewController時,請使用以下內容檢查模型中的對象是圖像還是字符串。
    if ([myObject class] == [UIImage class])
    {
    //HERE ASSIGN IT TO UIIMAGEVIEW.image
    }
    else
    {
    //HERE ASSIGN IT TO UILABEL.text
    }

後,如果您需要更多的幫助....

很抱歉,如果這不是你在找什麼.....

1

。將ImageView和標籤設置爲隱藏或在您需要的頁面上可見。

相關問題