programming4us
programming4us
MOBILE

iPad SDK : Popovers - The Font Name Popover (part 2)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. The Back End

Now it's time to implement the portions of DudelViewController that will fire up the FontListController, dismiss its popover when the user makes a selection, and grab the selected value. Start with an import:

#import "FontListController.h"

Then fill in this previously empty method:

- (IBAction)popoverFontName:(id)sender {
FontListController *flc = [[[FontListController alloc]
initWithStyle:UITableViewStylePlain] autorelease];
flc.selectedFontName = self.font.fontName;
[self setupNewPopoverControllerForViewController:flc];
flc.container = self.currentPopover;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(fontListControllerDidSelect:)
name:FontListControllerDidSelect
object:flc];
[self.currentPopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}

This method creates and configures a FontListController instance. Part of the configuration involves calling a method named setupNewPopoverControllerForViewController: (which we're going to create in just a minute). It also sets us up as an observer for a notification, which will tell us that the user selected something, and then displays a popover.

What's not really clear here is the final line, which contains self.currentPopover. We haven't set that, have we? Well, the following auxiliary method does! Insert this method somewhere above all the popover action methods:

- (void)setupNewPopoverControllerForViewController:(UIViewController *)vc {
if (self.currentPopover) {
[self.currentPopover dismissPopoverAnimated:YES];
[self handleDismissedPopoverController:self.currentPopover];
}
self.currentPopover = [[[UIPopoverController alloc] initWithContentViewController:vc]
autorelease];
self.currentPopover.delegate = self;
}


We'll use this method every time we're going to present a popover. By doing so, we save a few lines in each popover action method, and also ensure that we're doing things the same way each time. Now, I'm not going to pretend that this separate method sprang from my forehead in one piece.

Any time you find yourself doing cut-and-paste coding, consider chunking things off into separate methods, because someone is probably going to revisit your code someday. The mind you save may be your own.


So now we have code in place to fire up the popover, but we still need to handle the user selecting something. Begin by creating a method to be called when the notification we're observing is triggered:

- (void)fontListControllerDidSelect:(NSNotification *)notification {
FontListController *flc = [notification object];
UIPopoverController *popoverController = flc.container;
[popoverController dismissPopoverAnimated:YES];
[self handleDismissedPopoverController:popoverController];
self.currentPopover = nil;
}

Here, you see the reason for putting the container property in FontListController. After the user makes a selection, FontListController shoots off a notification. DudelViewController picks it up, and uses the container property to dismiss the popover. This method also calls the main handler for all our popovers, which you should now revise to this:

- (void)handleDismissedPopoverController:(UIPopoverController*)popoverController {
if ([popoverController.contentViewController isMemberOfClass:
[FontListController class]]) {
// this is the font list, grab the new selection
FontListController *flc = (FontListController *)
popoverController.contentViewController;
self.font = [UIFont fontWithName:flc.selectedFontName size:self.font.pointSize];
}
self.currentPopover = nil;
}


This is where the selection in the popover finally ends up having an effect. The font is now set according to what the user picked.

You should now be able to build and run the app, and then touch the font list button in the toolbar to see something like the popup shown in Figure 2.

Try selecting a different font, and then using the Text tool to create some text. Neat! You now have the full complement of fonts included with the iPad at your disposal. You're still stuck with just one size, so let's tackle that next.

Figure 2. Selecting a font
Other  
  •  Beginning Android 3 : Working with Containers - Tabula Rasa
  •  Beginning Android 3 : Working with Containers - LinearLayout Example & The Box Model
  •  iPhone Application Development : Reading and Writing User Defaults (part 2) - Implementing System Settings
  •  iPhone Application Development : Reading and Writing User Defaults (part 1) - Creating Implicit Preferences
  •  - Mobile Application Security : SMS Security - Overview of Short Message Service
  •  - Mobile Application Security : Bluetooth Security - Bluetooth Security Features
  •  Integrating Your Application with Windows Phone 7
  •  Introducing Windows Phone 7 Photo Features (part 2) - Using a Chooser to Open Photos & Saving Photos to the Phone
  •  Introducing Windows Phone 7 Photo Features (part 1) - Using a Chooser to Take Photos
  •  Mobile Application Security : Bluetooth Security - Bluetooth Technical Architecture
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us