Vinícius Maia Vinícius Maia - 1 year ago 182
iOS Question

Why do I get a "Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES" error in Xamarin iOS?

I created a TableView with a TableViewCell and always have the View opening. I have this error:

Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES

I'm using XIB file to design my TableViewCell and the TableView.

This is my TableView:

public partial class FavoriteProjectsView : MvxTableViewController<FavoriteProjectsViewModel>
public FavoriteProjectsView() : base("FavoriteProjectsView", null)

public override void ViewDidLoad()

// ios7 layout
if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
EdgesForExtendedLayout = UIRectEdge.None;

var source = new MvxSimpleTableViewSource(TableView, FavoriteProjectsItem.Key, FavoriteProjectsItem.Key);
TableView.Source = source;

this.CreateBinding(source).To<FavoriteProjectsViewModel>(viewModel => viewModel.Projetos).Apply();
this.CreateBinding(BtnSave).To<FavoriteProjectsViewModel>(viewModel => viewModel.SaveCommand).Apply();

var bounds = UIScreen.MainScreen.Bounds;
var carregamento = new CarregamentoIOS(bounds);

ViewModel.Carregamento = carregamento;

This is my TableViewCell:

public partial class FavoriteProjectsItem : MvxTableViewCell
public static readonly NSString Key = new NSString("FavoriteProjectsItem");
public static readonly UINib Nib = UINib.FromName("FavoriteProjectsItem", NSBundle.MainBundle);

protected FavoriteProjectsItem(IntPtr handle) : base(handle)
this.DelayBind(() =>
this.CreateBinding(LblName).To<Project>(project => project.Name).Apply();
this.CreateBinding(SwitchFavorite).To<Project>(project => project.IsFavorite).Apply();

public static FavoriteProjectsItem Create()
return (FavoriteProjectsItem)Nib.Instantiate(null, null)[0];

Answer Source

It seems you are using MvvmCross or some other Mvvm library?

It's only a guess at this point but it would seem that something, somewhere is setting a property _setHostsLayoutEngine:YES but that this setting requires Auto Layout constraints, which may have been disabled with a call on the view to view.TranslatesAutoresizingMaskIntoConstraints = false.

The old system of laying out views in iOS was to use something called AutoResizing. The AutoResizing flags can either be set in code or in the XIB/Storyboard. If you are using AutoLayout, the new and improved layout system that uses constraints and offers much more flexibility (and complexity), for the XIB/Storyboard then any AutoResizing flags should be converted automatically into constraints that can be used with the AutoLayout system. This is the default behavior, but can be disabled with the call noted above, view.TranslatesAutoresizingMaskIntoConstraints = false.

For more information about using AutoLayout with Xamarin iOS Designer, please see: