Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UIPageViewController Xamarin_C#_Xamarin.ios - Fatal编程技术网

C# UIPageViewController Xamarin

C# UIPageViewController Xamarin,c#,xamarin.ios,C#,Xamarin.ios,我需要在Visual Studio 2017 for mac中使用Xamarin实现一个简单的UIPageViewController 正如中的文档所述,我需要使用UIPageViewControllerDataSource.GetNextViewController和UIPageViewControllerDataSource.GetPreviousViewController委托连接上一个视图和下一个视图,但我不清楚应该在何处执行该操作,我也看不到任何地方可以使用故事板设计器来实现这一点 使

我需要在Visual Studio 2017 for mac中使用Xamarin实现一个简单的UIPageViewController

正如中的文档所述,我需要使用
UIPageViewControllerDataSource.GetNextViewController
UIPageViewControllerDataSource.GetPreviousViewController
委托连接上一个视图和下一个视图,但我不清楚应该在何处执行该操作,我也看不到任何地方可以使用故事板设计器来实现这一点


使用UIPageViewController的想法是在进入另一个视图之前添加一个4页的快速教程,在UIPageViewController的最后一个视图中会有一个按钮将segway调用到下一页。

您可以在情节提要中添加
UIPageViewController
。在Properties window=>Widget(导航、转换样式、脊椎位置)中配置样式

然后,您可以将
数据源
添加到相应的CS文件中。使用以下命令添加第一个显示的UIViewController:
SetViewController(新UIViewController[]{viewController},UIPageViewControllerNavigationDirection.Forward,true,null)。请注意,当您将
脊椎位置设置为
Mid
时,此数组应至少包含两个
UIViewController
。如果没有,只添加一个

但我不清楚该在哪里做,也不知道该在哪里做 使用故事板设计器

当您想导航到下一页时,将触发事件
GetNextViewController()
(即第一页-第二页)。您应该返回将在该事件中显示的控制器。另外
GetPreviousViewController()
表示返回时要显示的控制器。这是我的样本:

public class MyPageViewDataSource : UIPageViewControllerDataSource
{

    List<UIViewController> pageList;
    public MyPageViewDataSource(List<UIViewController> pages)
    {
        pageList = pages;
    }

    public override UIViewController GetNextViewController(UIPageViewController pageViewController, UIViewController referenceViewController)
    {           
        var index = pageList.IndexOf(referenceViewController);
        if (index < pageList.Count - 1)
        {
            return pageList[++index];
        }
        else
        {
            //when navigate to the last page, return null to disable navigate to next.
            return null;
        }
    }

    public override UIViewController GetPreviousViewController(UIPageViewController pageViewController, UIViewController referenceViewController)
    {
        var index = pageList.IndexOf(referenceViewController);
        if (index == 0)
        {
            //when navigate to the first page, return null to disable navigate to previous.
            return null;
        }
        else
        {
            return pageList[index - 1];
        }
    }
}
公共类MyPageViewDataSource:UIPageViewControllerDataSource
{
列表页面列表;
公共MyPageViewDataSource(列表页)
{
页面列表=页面;
}
公共覆盖UIViewController GetNextViewController(UIPageViewController pageViewController,UIViewController引用ViewController)
{           
var index=pageList.IndexOf(referenceViewController);
如果(索引<页面列表.计数-1)
{
返回页面列表[++索引];
}
其他的
{
//导航到最后一页时,返回null以禁用导航到下一页。
返回null;
}
}
公共覆盖UIViewController GetPreviousViewController(UIPageViewController pageViewController,UIViewController引用ViewController)
{
var index=pageList.IndexOf(referenceViewController);
如果(索引==0)
{
//导航到第一页时,返回null以禁用导航到上一页。
返回null;
}
其他的
{
返回页面列表[索引-1];
}
}
}

最后将
UIPageViewController
的数据源设置为:
DataSource=new MyPageViewDataSource(pageList)

如何创建
页面列表
对象?我尝试向视图添加名称,但无法引用它们。pageList是UIViewController列表。您可以构造一个只包含一个图像的新UIViewController。然后用你的ViewControllers初始化列表。我终于让它工作了!但是在我要浏览的页面底部没有任何指示器。如何添加页面指示器?这是另一个名为UIPageControl的控件。我看到了它,但我不知道如何以及在何处添加它