Pregunta

I was looking into Objective-C protocols and delegates and was trying to implement a custom one in Xamarin.iOS. I was following the example in the Xamarin documentation for "Binding Protocols"

[BaseType (typeof(NSObject))]
[Model][Protocol]
public interface INITableViewCellDelegate {

}

for some reason I cannot find the BaseType attribute. I cannot reference it. My current list of namespaces for the project are:

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using MonoTouch.ObjCRuntime;

I'm expecting that it should be under System or MonoTouch.ObjCRuntime. Can anyone shed some light? I've checked other questions on StackOverflow involving binding protocols and many examples show the same MonoTouch usings.

Thank you

¿Fue útil?

Solución

Make sure you are using an iOS Binding Project

enter image description here

Otros consejos

[BaseType] attributes are only used in projects of type "iOS Binding Project" and are not available at runtime.

So make sure you're doing an "iOS Binding Project" that'll be processed by the btouch tools and will generate bindings for your native library.

I had this same problem because I just blindly added the files that Sharpie creates to my project without thinking.

When you create a new iOS binding library, it creates two files: ApiDefinition.cs and Structs.cs. These are empty except for a namespace that matches the project name.

When Sharpie is run it creates two files: ApiDefinitions.cs and StructsAndEnums.cs. These are the pure definitions and do not exist in a namespace. Do not add these files to your project. Instead;

  1. Copy all the contents of ApiDefinitions.cs and paste it in the empty namespace in ApiDefinition.cs.
  2. Copy all the contents of StructsAndEnums.cs and paste it into the empty namespace in Structs.cs.

Hopefully it should now build.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top