使用按钮将 childViewController 加载到滚动视图父级 [英] Load childViewController to scrollview parent with a button

查看:62
本文介绍了使用按钮将 childViewController 加载到滚动视图父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PageViewController (https://www.cocoacontrols.com/controls/pageviewcontroller) 创建一个类似于 Wired 的杂志应用.

I'm using the PageViewController (https://www.cocoacontrols.com/controls/pageviewcontroller) to create a Magazine App similar to Wired.

我在 CustomPagerViewController 上使用了这段代码来加载子视图:

I've used this code on CustomPagerViewController to load the childview's:

- (IBAction)btn_index:(id)sender {

NSInteger currentPage = 3;
CGPoint offset = CGPointMake(currentPage * self.scrollView.frame.size.width, 0);
[self.scrollView setContentOffset:offset animated:YES];}

但是我需要 indexviewcontroller 上的几个按钮来加载正确的视图,当我使用相同的代码时,

But I need several buttons on the indexviewcontroller to load the correct views and when I use the same code,

在类型的对象上找不到属性scrollView"'Pag4_5ViewController *'

Property 'scrollView' not found on object of type 'Pag4_5ViewController *'

我已经搜索并尝试了几种方法,但都是徒劳的.

I've searched and tried several methods but all in vain.

有人知道如何解决这个问题吗?

Does anyone have any idea on how to solve this problem?

推荐答案

在聊天解决方案中找到后需要修复.问题是这个上下文(Pag4_5ViewController.m 文件)中的self 指向Pag4_5ViewController 的一个实例,并且需要访问CustomPagerViewController 类实例的方法.熟悉该项目后找到了解决方案.以及下面给出的实施例之一:

After talks in chat solution has been found and it is necessary to fix. The problem was that the self in this context (Pag4_5ViewController.m file) pointer to an instance of Pag4_5ViewController, and needed access to the methods of class CustomPagerViewController instance. After getting acquainted with the project found a solution. And one of the embodiments given below:

在 Pag4_5ViewController 类(和其他类)中添加行:

Add in Pag4_5ViewController class (and to other classes) line:

#import "CustomPagerViewController.h"

并将代码更改为如下所示:

and change code to something like this:

- (IBAction)btn_index:(id)sender
{
  CustomPagerViewController *parent = (CustomPagerViewController *)[self parentViewController];
  //page number where the transition will be accomplished
  NSInteger currentPage = 3;// 3 in Pag4_5ViewController.m file do nothing, because it is an index of the same page. But it be correct work for other pages.
  CGPoint offset = CGPointMake(currentPage * parent.scrollView.frame.size.width, 0);
  [parent.scrollView setContentOffset:offset animated:YES];
}

注意:这只是可以工作的代码的可能变体之一.但可能还有其他人.

Note: This is just one of the possible variants of the code that will work. But there may be others.

这篇关于使用按钮将 childViewController 加载到滚动视图父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆