Home>
I want to know what happens and how to make two buttons and labels that don't cause an error.

Hello, Mac on the official website – Tutorial
(Https://docs.microsoft.com/en-us/xamarin/mac/get-started/hello-mac)
When I tried to generate two buttons and labels in the same way, an error occurred.
The code where the error occurred was fixed once, but after the build, it was corrected to the code before the correction.
I don't understand why this happens, so please explain.
How can I generate multiple buttons in Xcode to prevent this error from occurring?
Professor

error code i am experiencing
/Users/xxxxxxx/Desktop/DevelopMacAPP/Hello_Mac/Hello_Mac/ViewController.designer.cs (22,22): Error CS0102: The type 'ViewController' already contains a definition for 'ClickedLabel' (CS0102) ( Hello_Mac)
Location of the problem/code i am experiencing
// WARNING
//
// This file has been generated automatically by Visual Studio to store outlets and
// actions made in the UI designer.If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace Hello_Mac
{
    [Register ("ViewController")]
    partial class ViewController
    {
        [Outlet]
        AppKit.NSButton ClickedLabel {get;set;}
        [Outlet]
        AppKit.NSTextField ClickLabel {get;set;}
        [Action ("ClickButton:")]
        partial void ClickButton (Foundation.NSObject sender);
        [Action ("ClickedLabel:")]
        partial void ClickedLabel (Foundation.NSObject sender);
        void ReleaseDesignerOutlets ()
        {
            // error here
            if (ClickedLabel! = null) {
                ClickedLabel.Dispose ();
                ClickedLabel = null;
            }
            if (ClickLabel! = null) {
                ClickLabel.Dispose ();
                ClickLabel = null;
            }
        }
    }
}
ViewController.h source code
// WARNING
// This file has been generated automatically by Visual Studio to
// mirror C # types. Changes in this file made by drag-connecting
// from the UI designer will be synchronized back to C #, but
// more complex manual changes may not transfer correctly.

#import<Foundation/Foundation.h>
#import 

@interface ViewController: NSViewController {
    NSButton * _ClickedLabel;
    NSTextField * _ClickLabel;
}
@property (nonatomic, retain) IBOutlet NSButton * ClickedLabel;
@property (nonatomic, retain) IBOutlet NSTextField * ClickLabel;
-(IBAction) ClickButton: (id) sender;
-(IBAction) ClickedLabel: (id) sender;
@end
  • Answer # 1

    ClickedLabelis the name. Please make either one a different name.
    When changing, change ViewController.h.
    If you change the name, you will also need to reconfigure the connection to the ViewController. (It ’s a circle with an arrow button.)

Related articles