如何在Carbon中获取应用程序菜单?

时间:2015-08-31 08:46:18

标签: objective-c macos-carbon nsmenu nsmenuitem

如何获取应用程序菜单的NSMenu(苹果菜单旁边菜单栏中的菜单)。

这对我的旧碳应用程序不起作用,mainMenu返回nil。

NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenu *appMenu = [[mainMenu itemAtIndex:0] submenu];

for (NSMenuItem *item in [appMenu itemArray]) {
    NSLog(@"%@", [item title]);
}

1 个答案:

答案 0 :(得分:0)

我不知道如何(或者是否可能)获得一个Carbon菜单的NSMenu参考,但我在我的一些旧代码中发现了这一点:

     public override View GetView(int position, View convertView, ViewGroup parent)
                {
                    if (convertView == null)
                    {

                        convertView = commentListActivity.LayoutInflater.Inflate(Resource.Layout.comment_list_row, null);
                         txtUserName = convertView.FindViewById<TextView>(Resource.Id.txtCommenterName);
                    txtCommentTime = convertView.FindViewById<TextView>(Resource.Id.txtCommenterTime);
                    imgUserImage = convertView.FindViewById<ImageView>(Resource.Id.imgProfileUserImage);
                    txtCommentText = convertView.FindViewById<TextView>(Resource.Id.txtCommentText);
                    ibtnEdit = convertView.FindViewById<ImageButton>(Resource.Id.imgBtnEdit);
                    itbtnDelete = convertView.FindViewById<ImageButton>(Resource.Id.imgBtnDelete);
                    }


                    Comments mComments = dummyCommentList.ElementAt(position);

                    txtUserName.Text = mComments.UserName;
                    txtCommentTime.Text = mComments.CommentTime;

                    txtCommentTime.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
//do what you want here

}
                    });


                   return convertView;
                }