Am porting an iOS application from Swift on Xcode to C# on Visual Studio 15. I need to do some dynamic arrangement of UITextViews, and need to instantiate a new instance of NSLayoutConstraint to facilitate that. When I try to create it directly via a new instance:
constraint = new NSLayoutConstraint( toField, toAlignment, NSLayoutRelation.Equal, fromField, fromAlignment, 1, 0);
I get the error ‘No matching overload’.
When I look at the popup for the NSLayoutConstraint(), it gives me two parameter list options:
NSLayoutConstaint.init() : instancetype
and
NSLayoutConstraint.$New(view1: rtl.id!) attribute (attr1: NSLayoutAttribute) relatedBy (relation: NSLayoutRelation) toItem (view2: rtl.id) attribute (attr2:NsLayoutAttribute) multiplier (multiplier: CGFloat) constant (c: CGFloat) : Instancetype
Looking at the NSLayoutConstraint metadata, it says that the definition is:
public static this withItem(id! view1) attribute(NSLayoutAttribute attr1) relatedBy(NSLayoutRelation relation) toItem(id view2) attribute(NSLayoutAttribute attr2) multiplier(CGFloat multiplier) constant(CGFloat c);
In both cases, it seems to match the parameters required in Swift on Xcode (the original code works fine there). I’ve tried casting the toField/fromField values, which are the only ones which do not explicitly match the parameter list types, to no avail. I’ve also played around with the last two float parameters just in case the compiler isn’t automatically casting them. Nothing seems to work.
Are there any differences in the calling method from C#? Is there some documentation page containing precise details on how to translate the various UI calls which I haven’t found?
Thanks,
Andrew