Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xelhark

macrumors newbie
Original poster
Jul 16, 2010
7
0
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
Code:
@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:
Code:
@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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.