Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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/7/elixir/2.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 iOS Center TableViewCell子视图_Ios_Xamarin_Xamarin.ios_Icarousel - Fatal编程技术网

Xamarin iOS Center TableViewCell子视图

Xamarin iOS Center TableViewCell子视图,ios,xamarin,xamarin.ios,icarousel,Ios,Xamarin,Xamarin.ios,Icarousel,我将NuGet包iCarousel用作UITableViewCell中的子视图。 以下是添加iCarousel对象的代码(此代码位于父ViewController的ViewDidLoad方法中): 现在我想垂直和水平地将iCarousel居中。因此,我添加了以下代码: NSLayoutConstraint centerX = carousel.CenterXAnchor.ConstraintEqualTo(this.CarouselViewCell.ContentView.CenterXAnch

我将NuGet包iCarousel用作UITableViewCell中的子视图。 以下是添加iCarousel对象的代码(此代码位于父ViewController的ViewDidLoad方法中):

现在我想垂直和水平地将iCarousel居中。因此,我添加了以下代码:

NSLayoutConstraint centerX = carousel.CenterXAnchor.ConstraintEqualTo(this.CarouselViewCell.ContentView.CenterXAnchor);
NSLayoutConstraint centerY = carousel.CenterYAnchor.ConstraintEqualTo(this.CarouselViewCell.ContentView.CenterYAnchor);

centerX.SetIdentifier("centerXCostraint");
                centerY.SetIdentifier("centerYConstraint");

var centerConstraints = new[] {centerX, centerY };
CarouselViewCell.ContentView.TranslatesAutoresizingMaskIntoConstraints = false;
                CarouselViewCell.ContentView.AddConstraints(centerConstraints);
我的问题是,现在应用程序在这一行崩溃:

CarouselViewCell.ContentView.AddConstraints(centerConstraints);
我在一篇类似的文章中发现,您需要向关联的UIView对象添加约束。我试了几样东西,但都没有成功

CarouselViewCell.ContentView.AddConstraints(中心约束)

这段代码将崩溃,因为我们需要先添加控件,然后设置其约束。否则它会崩溃。尝试调整代码的顺序:

//Let this code just lie after the carousel's construction.
CarouselViewCell.ContentView.AddSubview(carousel);
此外,如果要添加旋转木马的约束,应将旋转木马的
翻译自动调整大小GMaskintoConstraints
设置为
false
not
CarouselViewCell.ContentView

此外,根据您的描述,我认为您希望在UITableViewCell上安装iCarousel。此配置应在单元格类中设置,而不是在父ViewController类中设置

CarouselViewCell.ContentView.AddConstraints(中心约束)

这段代码将崩溃,因为我们需要先添加控件,然后设置其约束。否则它会崩溃。尝试调整代码的顺序:

//Let this code just lie after the carousel's construction.
CarouselViewCell.ContentView.AddSubview(carousel);
此外,如果要添加旋转木马的约束,应将旋转木马的
翻译自动调整大小GMaskintoConstraints
设置为
false
not
CarouselViewCell.ContentView

此外,根据您的描述,我认为您希望在UITableViewCell上安装iCarousel。此配置应在单元格类中设置,而不是在父ViewController类中设置