Xamarin iOS Center TableViewCell子视图
我将NuGet包iCarousel用作UITableViewCell中的子视图。 以下是添加iCarousel对象的代码(此代码位于父ViewController的ViewDidLoad方法中): 现在我想垂直和水平地将iCarousel居中。因此,我添加了以下代码: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
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
notCarouselViewCell.ContentView
此外,根据您的描述,我认为您希望在UITableViewCell上安装iCarousel。此配置应在单元格类中设置,而不是在父ViewController类中设置
CarouselViewCell.ContentView.AddConstraints(中心约束)
这段代码将崩溃,因为我们需要先添加控件,然后设置其约束。否则它会崩溃。尝试调整代码的顺序:
//Let this code just lie after the carousel's construction.
CarouselViewCell.ContentView.AddSubview(carousel);
此外,如果要添加旋转木马的约束,应将旋转木马的翻译自动调整大小GMaskintoConstraints
设置为false
notCarouselViewCell.ContentView
此外,根据您的描述,我认为您希望在UITableViewCell上安装iCarousel。此配置应在单元格类中设置,而不是在父ViewController类中设置