views:

419

answers:

1

Hi,

I'm not sure I'm phrasing this properly, but basically I do this in my main app delegate:

Application *app = [[Application alloc] initWithApplication:fullPath]

The Application class has an initWithApplication method that takes in the path of an app and then sets the properties for appPath, name, etc. Then I add the new "app" object to the applications NSMutableArray:

if (app) [applications addObject: app];

The NSArrayController's content array is bound to the applications NSMutableArray, and then the various keys (appPath, name, etc) are set in the NSArrayController. I then have a table view with various columns bound to the different properties, e.g. one column for the name, one column from the path, etc.

I then have a launch button that launches the app that is selected in the table view. For this I use this code:

Application *app = [applications objectAtIndex:[tableView selectedRow]];

Then I just use "app.appPath" as a reference to the path of the currently selected item. This works fine. The problem comes in when the table view contents are filtered using a filterPredicate. Basically it filters out all apps in the table view and leaves only the ones with a name that contains the phrase typed into the search box.

The above method does not work because it gets the index of the item in the table view, and since all the items are not in the table view, the count gets messed up. For example say I have an app called MyApp.app which is item at index 25 of the applications array.

The above code works well because the tableView and the applications array have the same number of objects. However filtering out the contents of the table view creates a difference in the number of objects, and therefore it launches the wrong app.

I hope my explanation is not too confusing, but its hard to explain. Any way around this?

Thanks

A: 

Solution was pretty simple for anyone that wants to know:

[[arrayController selection] valueForKey:@"appPath"]

HTH

macatomy