A.8. Chapter 8

A.8.1. Exercise 1 solution

  1. In Xcode, add the following method to SlideShowWindowController.m's PrivateMethods category:

    - (void)tableDoubleClick:(id)sender;
  2. Set the table view's double-click action using the following line of code. You need to add this line to SlideShowWindowController's windowDidLoad method.

    [mTableView setDoubleAction:@selector(tableDoubleClick:)];

    Normally, double-clicking a row in a table view begins an editing session; this is a common way of changing contents in a table view. If the rows in a table view aren't editable, the table view sends a double-click action along the responder chain. NSTableView doesn't have a double-click action by default, so you must supply one if you are interested in handling double-clicks. The double-click action otherwise behaves just like an NSControl instance's action.

  3. Define the following tableDoubleClick: method in SlideShowWindowController's Table View Support section.

    - (void)tableDoubleClick:(id)sender
    {
        int row = [sender clickedRow];
    
        if (row != −1) {
            Slide *slide = [[self document] slideAtIndex:row];
    NSString *path = [slide filePath];
    
            [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfFile:path display:YES];
        }
    }

    The NSDocumentController singleton class is responsible, among other things, for keeping track of the kinds of documents your application is capable of opening. You can ask the NSDocumentController to open a file at a specific path. If the application is capable of displaying ...

Get Beginning Mac OS® X Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.