13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

336CHAPTER 9: Writing an ApplicationTo use the menu item, you need an action method. Open APAppDelegate.h and add the codefrom Listing 9-80.Listing 9-80. The Browse Action Method- (IBAction)browseRemoteStores:(id)sender;- (void)attachToRemoteAddressBookWithName:(NSString *)namehandler:(void (^)(id, NSError *)) handler;You now have both the action for the menu item and one to use when the user has chosen aremote address book to which to connect. In the interface editor, Control-drag a connectionfrom the new menu item to the App Delegate and choose the -browseRemoteStores: method asits action.Open APAppDelegate.m and locate the -vendAddressBook: method. Type the code fromListing 9-81 below it to implement this action method.Listing 9-81. Requesting a Service Browser- (IBAction)browseRemoteStores:(id)sender{if ( _browser == nil )[self _initializeNetworker];}[_browser availableServiceNames: ^(id result, NSError *error) {dispatch_async(dispatch_get_main_queue(), ^{if ( error != nil ){[NSApp presentError: error];}else{_browserWindow = [[APRemoteBrowserWindowController alloc]initWithServiceNames: result delegate: self];[_browserWindow showWindow: self];}});}];This code calls the XPC method -availableServiceNames:, and its reply block passes on the(successful) results to a new window controller object, APRemoteBrowserWindowController.Quickly skip to the top of the file and add an import statement forAPRemoteBrowserWindowController.h.There’s also a new instance variable involved: _browserWindow, which holds a reference to thebrowser’s window controller. Add that into the class’s @implementation block. Now let’s createthat new class.In Xcode, add a new file to the application target; make it a subclass of NSWindowController andgive it the name just discussed. Also ensure that the “With XIB for user interface” button is checked.When the files have been created, open APRemoteBrowserWindowController.h.www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!