Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
向Xamarin CarouselPage动态添加项目在IOS中不起作用_Ios_Xamarin_Carousel - Fatal编程技术网

向Xamarin CarouselPage动态添加项目在IOS中不起作用

向Xamarin CarouselPage动态添加项目在IOS中不起作用,ios,xamarin,carousel,Ios,Xamarin,Carousel,我有一个可以部署到Android和IOS的项目。在公共项目中,我有一个旋转木马。我有一个ProductPage,它被动态地添加x次到CarouselPage,以便于显示类别中的项目。ProductPage上的图像项是超链接引用(http://www.xxx.com/image/yyy.png 例如)。选择类别将打开一个带有ListView的页面,用户可以滚动并选择一个产品,该产品将打开旋转木马页面并填充它,从而使ListView中选择的产品成为当前正在查看的项目。然后,用户可以在旋转木马中来回滚

我有一个可以部署到Android和IOS的项目。在公共项目中,我有一个旋转木马。我有一个ProductPage,它被动态地添加x次到CarouselPage,以便于显示类别中的项目。ProductPage上的图像项是超链接引用(http://www.xxx.com/image/yyy.png 例如)。选择类别将打开一个带有ListView的页面,用户可以滚动并选择一个产品,该产品将打开旋转木马页面并填充它,从而使ListView中选择的产品成为当前正在查看的项目。然后,用户可以在旋转木马中来回滚动,查看类别中每个项目的详细信息页面

现在,产品详细信息页面上有一个可拖动的项目,移动它会尝试滚动旋转木马,因此我更改了代码,以便在解决此问题之前,一次只能将一个项目加载到旋转木马页面中。产品页面上有“上一步/下一步”按钮,以便于在目录中滚动,因为滑动操作被暂时禁用

下面是填充添加到旋转木马的产品视图的代码

            carPages = new List<ProductPage>();

            foreach (cwImage image in selectedCategory.cwImages)
            {
                pageCount++;
                var newContentPage = new ProductPage();

                //This converts the image name to a hyperlink
                var imgSource = string.Concat(cwSettings.CategoryData.BaseUrl, image.ImageUrl);
                newContentPage.pageNumber = pageCount;

                //Set the image source to the hyperlink
                newContentPage.WrapImage.Source = ImageSource.FromUri(new Uri(imgSource));
                newContentPage._textColor = (Color)(converter.ConvertFromInvariantString(image.DefaultColor));

                //Add to list
                carPages.Add(newContentPage);

                var selectedImage = imageUrl.ToString().Replace("Uri: " + cwSettings.CategoryData.BaseUrl, "");
                if (image.ImageUrl == selectedImage)
                {
                    //Make this page the current page
                    Children.Add(newContentPage);
                    CurrentPage = (ContentPage)newContentPage;
                }

            }
carPages=新列表();
foreach(在selectedCategory.cwImages中的cwImage图像)
{
pageCount++;
var newContentPage=新产品页();
//这会将图像名称转换为超链接
var imgSource=string.Concat(cwSettings.CategoryData.BaseUrl,image.ImageUrl);
newContentPage.pageNumber=页面计数;
//将图像源设置为超链接
newContentPage.WrapImage.Source=ImageSource.FromUri(新Uri(imgSource));
newContentPage._textColor=(颜色)(converter.ConvertFromInvariantString(image.DefaultColor));
//添加到列表中
carPages.Add(newContentPage);
var selectedImage=imageUrl.ToString().Replace(“Uri:+cwSettings.CategoryData.BaseUrl,”);
if(image.ImageUrl==selectedImage)
{
//使此页成为当前页
添加(newContentPage);
CurrentPage=(ContentPage)newContentPage;
}
}
底线是,这在Android上就像魔术一样,但在IOS上旋转木马页面总是空白的,我不知道为什么。代码按预期执行,IOS预览器正确显示页面。我试着用一个哑页代替ProductPage,同样的结果;它会显示在IOS预览器中,但不会显示在应用程序中。ProductPage的类型为ContentPage

我正在Windows 10上使用Visual Studio 2017


非常感谢您的帮助

,因为它在Android中使用相同的代码,通过您的描述,我认为iOS中的问题在于图像加载不正确

所以,请检查一下

将以下键值添加到info.plist,以完全禁用所有域和internet的ATS,否则它将阻止以http开始的web链接:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads

由于它在Android中使用相同的代码,通过您的描述,我认为iOS中的问题在于图像加载不正确

所以,请检查一下

将以下键值添加到info.plist,以完全禁用所有域和internet的ATS,否则它将阻止以http开始的web链接:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads

不起作用。即使我从ProductPage视图中删除图像,页面也不会显示。您的意思是该页面尚未添加到旋转木马页面吗?你能在那里添加一个断点来检查代码是否执行了吗?代码正在执行。我重组了逻辑。它在Android中仍然有效,现在我第二次尝试打开转盘页面时在IOS中遇到了这个错误。DetailPage是旋转木马,ProductPage是作为子对象添加到旋转木马的实例。代码与上面的代码非常接近,并且都在同一名称空间中。---------------------------------------------------------------System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键“CurbWrap.Catalog.ProductPage”。此错误通常在ProductPage不存在或未初始化时发生。我需要看更多的代码来找出原因。我重写了页面以不使用旋转木马。我认为这是一个iOS错误,我觉得我没有时间去花,期限很紧。没有工作。即使我从ProductPage视图中删除图像,页面也不会显示。您的意思是该页面尚未添加到旋转木马页面吗?你能在那里添加一个断点来检查代码是否执行了吗?代码正在执行。我重组了逻辑。它在Android中仍然有效,现在我第二次尝试打开转盘页面时在IOS中遇到了这个错误。DetailPage是旋转木马,ProductPage是作为子对象添加到旋转木马的实例。代码与上面的代码非常接近,并且都在同一名称空间中。---------------------------------------------------------------System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键“CurbWrap.Catalog.ProductPage”。此错误通常在ProductPage不存在或未初始化时发生。我需要看更多的代码来找出原因。我重写了页面以不使用旋转木马。我认为这是一个iOS错误,我觉得我没有时间去花,最后期限很紧。