partial void ClickedButton (Foundation.NSObject sender) { // Update counter and label ClickedLabel.StringValue = string.Format("The button has been clicked {0} time{1}.",++numberOfTimesClicked, (numberOfTimesClicked < 2) ? "" : "s"); }
此代码会附加到在 Xcode 和 Interface Builder 中创建的操作,且每次用户点击按钮时都会调用此代码。
2. 代码提示错误
No defining declaration found for implementing declaration of partial method 'ViewController.ClickedButton(NSObject)'
partial void ClickedButton(AppKit.NSButton sender) { // Update counter and label ClickedLabel.StringValue = string.Format("The button has been clicked {0} time{1}.", ++numberOfTimesClicked, (numberOfTimesClicked < 2) ? "" : "s"); }