在我的iPad应用程序中。我正在使用UIPageViewController,我想在一个页面上设置文本,在另一个页面设置图像。我试了很多,也在谷歌上搜索过,但没有找到任何解决方案。它正在消磨我的时间,所以如果有人做过它,请指导我并发布示例代码。
我使用了下面链接中的代码
http://www.ioslearner.com/implementing-uipageviewcontroller-programatically-without-storyboarding/
这是示例代码。我使用了contentviewcontroller。
我想使用两个带有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;
}
}
如果我理解得很好,那么在ContentPageView.xib文件中添加一个imageView并制作的出口。在所需页面上设置ImageView和标签隐藏或可见。
以下步骤对有帮助
- 在ContentViewController中保留UILabel和UIImageView
- 在modelArray中添加UIImage或NSString
- 当您制作一个新的ContantViewController时,请使用以下方法检查模型中的对象是图像还是字符串。
if ([myObject class] == [UIImage class])
{
//HERE ASSIGN IT TO UIIMAGEVIEW.image
}
else
{
//HERE ASSIGN IT TO UILABEL.text
}
如果您需要更多帮助,请发帖。。。。
很抱歉,如果这不是你想要的。。。。。