我试图从Monobjc的Monobjc桥中添加NSStatusItem。
该函数被调用,并且不会引发异常,但是我的图标没有出现:(。
这是我的代码:
#define DEBUG_APP
using System;
using Monobjc.Cocoa;
using Monobjc;
namespace YvanSoftware.TwitMenu
{
[ObjectiveCClass]
public class TwitMenuController : NSObject
{
[ObjectiveCField]
NSStatusItem _statusItem;
[ObjectiveCMessage("awakeFromNib")]
public void AwakeFromNib()
{
try {
if (_statusItem == null) {
NSMenu menu = new NSMenu("");
_statusItem = NSStatusBar.SystemStatusBar.StatusItemWithLength(32f);
_statusItem.Image = NSImage.ImageNamed("twitter.png");
NSMenuItem menuItem = new NSMenuItem("Send tweet!",new IntPtr(),"");
menuItem.ActionEvent += new ActionEventHandler(showTweetWindow);
menu.AddItem(menuItem);
_statusItem.Menu = menu;
DebugPrint("Status item added??");
}
} catch (Exception ex) {
DebugPrint(ex.Message);
}
}
public TwitMenuController(IntPtr i) : base(i) {}
public TwitMenuController() {}
public void showTweetWindow(Id sender) {
Console.WriteLine("Not implemented. (0x01)");
}
[ObjectiveCMessage("showAbout:")]
public void showAbout() {
Console.WriteLine("Not implemented (0x02)");
}
void DebugPrint(string s) {
#if DEBUG_APP
Console.WriteLine("*** DEBUG: " + s + " ***");
#endif
}
}
}
提前致谢,
伊万
最佳答案
创建变量后,必须立即保留_statusItem
变量:
_statusItem = NSStatusBar.SystemStatusBar.StatusItemWithLength(32f);
_statusItem.Retain();
关于c# - Monobjc::添加NSStatusItem,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2167378/