1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

What's the best approach in this case?

Discussion in 'Mac Programming' started by xelhark, Jun 25, 2013.

  1. macrumors newbie

    I am creating a small app, I'm using it mainly to learn how to properly program in Objective-C and cocoa.

    So, there's this Outline view which displays a tree hierarchical structure of data, and a collection view of other items. The leaf items from the outline view should be associated by the user to the items in the collection view, so there is a button to do that.

    This button should only be clicked when I have a single leaf object selected and a single item selected in the collection view.

    So I made two properties
    @property (readonly) Media *selectedMedia;
    @property (readonly) MediaInfo *selectedInfo;
    //---- .m
    - (Media*) selectedMedia{
        return [mediaOutlineView itemAtRow:[mediaOutlineView selectedRow]];
    - (MediaInfo*) selectedInfo{
        if([searchResultController.selectedObjects count] == 1){
            return [searchResultController.selectedObjects objectAtIndex:0];
        return nil;
    And a third boolean property:
    @property (readonly) BOOL canAssociate;
    //--------- .m
    - (BOOL) canAssociate{
        return ([self selectedMedia] && [self selectedInfo]);
    I used cocoa bindings to enable the button to the 'canAssociate' response, but this should change whenever the user clicks on a leaf node on the outline view or clicks on the collection view.

    How do I do that? What's the best approach to do this kind of things? Is this good enough?

    Thanks for your time

Share This Page