Partial Class Declaration Error in MonoTouch Hello

2019-09-15 02:05发布

问题:

I'm trying out the Hello World tutorial in the MonoTouch Trial version and I have put in all the code and attempted a build.

In the designer.cs file, the line

partial void actBtn (MonoTouch.Foundation.NSObject sender)

gives an error of

A partial method 'HelloWorld_iPhone.HelloWorld_iPhoneViewController.actBtn (MonoTouch.Foundation.NSObject sender)' implementation is missing a partial method declaration.

What did I miss?

I should add that this line was inserted automatically by MonoTouch - I only wrote the single line of method code which follows.

回答1:

I have never tried monotouch but one think ticks here ->

Looking at the code in question, can we have a partial method in c# and monotouch??

I have used partial class but we cannot declare a partial method.

partial cannot be used as a access modified for methods.



回答2:

The way the tutorial reads, it implies that you put the code in the Designer.cs file. That's wrong. The code they are showing you actually goes in the Controller.cs file.

Here's what you add to the Controller.cs file:

partial void actnButtonClick (MonoTouch.Foundation.NSObject sender) { this.lblOutput.Text = "Action button " + ((UIButton)sender).CurrentTitle + " clicked."; }



回答3:

I could achieve it by putting the statement in the file controller.cs.

In my example this way:

partial void action1 (MonoTouch.Foundation.NSObject sender);

and in my designer.css:

[Action ("action1:")]
partial void action1 (MonoTouch.Foundation.NSObject sender){
    this.lblOutput.Text=" Action 1 activated";
}

which means that the statement is in a separate class, and implementation in the designer.