Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to organize ViewControllers in a Monotouch project in MonoDevelop?

Working in MonoDevelop on an iOS app and I have the need to start organizing some of my files into subdirectories.

I have started off by creating a new ViewControllers folder in the main directory of the project. Mainly, I've just tried dragging and dropping the files that the Xcode storyboard creates into this new folder. This gives me errors of files missing, and sometimes I have had to manually edit the storyboard files to remove the or fix the location of the files.

While I have had some success with this, sometimes this also ends up with the storyboard files not updating the designer.cs files after making changes in Xcode.

Has anyone found the correct way to organize a large project without these issues?

like image 337
cain Avatar asked Nov 04 '22 08:11

cain


1 Answers

Take a look on this Bug Report on Xamarin: Bug 6130 - Moving files with dependency breaks reference.


The DependentUpon attribute in a csproj file is not updated after the parent file is moved. For example, creating a new controller class on Xamarin Studio and then moving it to a subfolder breaks the dependency.

The only way to fix it is via manual edit of the csproj and reloading the project in Xamarin Studio. You have to do this every time you add a new file.

It looks like Xamarin Studio adds instead of updates the existing entries in csproj. Here is csproj before I moved the files into a subfolder:

<Compile Include="TestViewController.cs" />
<Compile Include="TestViewController.designer.cs">
  <DependentUpon>TestViewController.cs</DependentUpon>
</Compile>

After Moving the files into the Controller subfolder.

<Compile Include="TestViewController.designer.cs">
  <DependentUpon>TestViewController.cs</DependentUpon>
</Compile>
<Compile Include="Controller\TestViewController.cs" />
<Compile Include="Controller\TestViewController.designer.cs">
  <DependentUpon>TestViewController.cs</DependentUpon>
</Compile>
like image 105
Alexandre Marcondes Avatar answered Jan 04 '23 13:01

Alexandre Marcondes