简体   繁体   中英

Populate SourceList in Xamarin.Mac app

I am creating my first Mac application using Mono and Xamarin Studio since I plan on reusing some C# code I have from a Windows version. So I am completely new to both XCode and Mono. I have just started to learn all the Cocoa stuff.

I am trying to create a sidebar similar to the one in Finder which I want to use for navigation. I have so far figured out I should use the SourceList object and have added it to my interface using the Interface Builder in XCode. But how do I populate it with headers and items (with icons)?

By default I see a sample header and a sample item in the IB but they don't show up when I run my app from Xamarin Studio. The SourceList is just empty.

Has anyone else done something similar to this? I can't find any good examples or tutorials on how to properly populate the SourceList.

EDIT:

I have now finally found the answer. It is a combination of the answer here by TheNextman and also his answer to a follow-up question here: Create NSView programatically in Xamarin Studio

This answer will help you populate the source list (which is just a styled NSOutlineView) with data.

Since the source list is 'view based', you will need to implement a couple of extra methods from the NSOutlineViewDelegate protocol. Off the top of my head:

outlineView:isGroupItem: - specify whether the item is a 'header' or not outlineView:dataCellForTableColumn:item: - return the cell for the given column/item

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM