1

I am working on developing a control that behaves same as NSPopUpButton , but should have a custom view as its MenuItem.In the custom view , I will have to show some texts (labels) and a tableView.

I was able to create a NSPopUpButton with a custom view following the sample code given by Apple in the following link ,

https://developer.apple.com/library/mac/samplecode/MenuItemView/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004136

However when I bind my tableView to an array controller , the tableView is always empty.When I try printing the arrangedObjects of the ArrayController , the results are as expected.Also the labels in the custom view are loading fine. The problem seems to happen only with the tableView.

Any ideas on this will be helpful.

Thanks.

1 Answers1

0

Fixed this by creating a NSMenuItem by allocating it.In the POC given in the Apple doc ,The menu item is created by the following code ,

viewCopyData = [NSArchiver archivedDataWithRootObject:<myCustomView>];
viewCopy = [NSUnarchiver unarchiveObjectWithData:viewCopyData];
menuItem = [menu itemAtIndex:1];
[menuItem setView:viewCopy];
[menuItem setTarget:self];

When myCustomView is having a table view ,the delegate methods of the table view are not being called when the menu item is created using viewCopyData = [NSArchiver archivedDataWithRootObject:<myCustomView>];

Creating it with ,

NSMenu *newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Custom"]; NSMenuItem *newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[self.title] action:@selector(someMethod:) keyEquivalent:@""];

Adding this menu item as the view of the menu item calls the tableview delegate methods in myCustomView.