Binding iOS embedded Framework for Xamarin END UP give exception?

BrightLeeBrightLee KRMember ✭✭✭
edited August 2016 in Xamarin.iOS

Please help my last step. Thanks.

I'm testing binding iOS native framework to Xamarin library.

-step 1- I created iOS framework and added MyView.h, MyView.m

MyView.m
(instancetype)initWithFrame:(CGRect)frame { id p = [super initWithFrame:frame]; self.backgroundColor = [UIColor greenColor];
return p; }

MyView.h
@interface MyView : UIView @end

very simple framework.

-step 2- add that MyView.h into Public Header and Made universal framework for any architecture. This framework now has

firstfile.h, MyView.h
two files as public headers

-step 3- I created iOS test app (single VC app) and tried this framework.

MyView *v = [[MyView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; [self.view addSubview:v];

It worked as I expected. It drew a green box.

-step 4- I created Xamarin Library project and import this framework file on Native Reference Folder by clicking right click and add file

-step 5- Add this lines to ApiDefinition.cs in Xamarin Library

[BaseType(typeof(UIView))] interface MyView { [Export ("initWithFrame:")] IntPtr Constructor (CGRect frame); }

build OK.

-step 6- I created Xamarin.iOS app and import this library to solution and test it.

MyView v = new MyView(new CGRect(0, 0, 100, 100)); this.View.AddSubview(v);

BUILD OK! but runtime error.

Exception has been thrown by the target of an invocation.

As I'm new with CSharp and mono. It was not easy to come here, Could you help me little bit at this point?

My clue is that there should be something pointing MyView.h in No.5 step. But I don't know what should be there.

Answers

Sign In or Register to comment.