question

marc-8366 avatar image
0 Votes"
marc-8366 asked KyleWang-MSFT answered

Xcode interface builder

I am using the xcode interface builder to build the UI, when I drag the touch event to header file, it generates following code in my C# project
file

x.designer.cd
[Action ("NextAction")]
partial void NextAction (Foundation.NSObject sender)


I also see it in both the header file and the m file, but the x.cs file does not generate any touch code in

x.cs file anymore. I am wondering if it is a bug or i am doing wrong using the xcode interface builder. I have say the current xamarin tutorial is not up to date anymore, specially the event binding part.

,



dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleWang-MSFT avatar image
0 Votes"
KyleWang-MSFT answered

Hi marc-8366,

Welcome to our Microsoft Q&A platform!

About Designing user interfaces with Xcode, you can refer to this document.

Usually, we only need to drag the control into the .h file as follows.

 @property (nonatomic, retain) IBOutlet UIButton *btn;

which will generate the corresponding code in designer.cs.

 [Outlet]
 UIKit.UIButton btn{get; set;}

And now, you can subscribe to the event in ViewDidLoad.

 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
        
     btn.TouchUpInside += Btn_TouchUpInside;
 }
    
 private void Btn_TouchUpInside(object sender, EventArgs e)
 {
     Console.WriteLine("Btn test");
 }

Regards,
Kyle


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.