Xcode interface builder

marc 101 Reputation points
2021-07-03T19:26:21.337+00:00

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.

,

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kyle Wang 5,531 Reputation points Microsoft External Staff
    2021-07-05T07:58:52.447+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.