如何跳转到pageViewController中的特定页面

时间:2014-09-10 09:55:07

标签: ios iphone ios7

我正在我的应用程序中使用pageviewcontroller,我正在从app委托类中的db检索图像,以便图像加载一次。 我面临的问题是我想指向该数组中的特定图像,但它指向第一个图像。

2 个答案:

答案 0 :(得分:0)

因此,当你有你的图像数组(即imageArray)时,你可以查看下面的代码,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  //As user taps on row of tableview then this method gets called so you will get the tapped row.
  NSLog(@"%d",indexPath.row);

  //With below you will get that image form your array using the row user has tapped.
  UIImage *image = [imageArray objectAtIndex:indexPath.row];

  //Now you pass that image to ur pageViewController and show it to ur user.
}

据我了解您的查询,这可能是您的解决方案。如果有的话,请告诉我。

答案 1 :(得分:0)

尝试此代码,因为您提到要从该类别索引显示到最后一个索引。这里有pagetile和pageimages是数组

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
if (index == NSNotFound) {
    return nil;
}
index++;
if (index == [self.pageTitles count]) {
    return nil;
}
return [self viewControllerAtIndex:index];
}

- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count])) {
    return nil;
}
// Create a new view controller and pass suitable data.
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageContentViewController"];
pageContentViewController.imageFile = self.pageImages[index];
pageContentViewController.titleText = self.pageTitles[index];
pageContentViewController.pageIndex = index;
return pageContentViewController;
}