ToolbarSearch

This sample shows how to use a search field in a toolbar. When you start a search, a table view displaying recent searches matching the current search string is displayed in a popover.

New controller:

  1. UIPopoverControllerDelegate

Create a navigation controller to contain the recent searches controller, and create the popover controller to contain the navigation controller.

  1. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:recentSearchesController];
  2.    
  3.     UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
  4.     self.recentSearchesPopoverController = popover;
  5.     recentSearchesPopoverController.delegate = self;

delegate methods of UIPopoverControllerDelegate

  1. /* Called on the delegate when the popover controller will dismiss the popover. Return NO to prevent the dismissal of the view.
  2.  */
  3. - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController;
  4.  
  5. /* Called on the delegate when the user has taken action to dismiss the popover. This is not called when -dismissAnimated: is called directly.
  6.  */
  7. - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController;

 

KeyboardAccessory

This sample shows how to use a keyboard accessory view.
You can create the accessory view programmatically (in code), in the same nib file as the view controller’s main view, or from a separate nib file. This example illustrates the latter; it means the accessory view is loaded lazily — only if it is required.

  1. - (BOOL)textViewShouldBeginEditing:(UITextView *)aTextView {    
  2.     [[NSBundle mainBundle] loadNibNamed:@"AccessoryView" owner:self options:nil];
  3.     // Loading the AccessoryView nib file sets the accessoryView outlet.
  4.     textView.inputAccessoryView = accessoryView;    
  5.     // After setting the accessory view for the text view, we no longer need a reference to the accessory view.
  6.     self.accessoryView = nil;
  7.    
  8.     return YES;
  9. }

We will get this result

 

SimpleGestureRecognizers

This sample shows how to use standard gesture recognizers.
A view controller creates four gesture recognizers to recognize a tap, a right swipe, a left swipe, and a rotation gesture. When they recognize a gesture, the recognizers send a suitable message to the view controller, which in turn displays an appropriate image at the location of the gesture.

New delegate

  1. UIGestureRecognizerDelegate

Create a rotation gesture recognizer, similar create a swipe gesture recognizer to recognize right swipes (the default).
We’re only interested in receiving messages from this recognizer, and the view will take ownership of it, so we don’t need to keep a reference to it.

  1. recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationFrom:)];
  2.     [self.view addGestureRecognizer:recognizer];
  3.     [recognizer release];

Create a tap recognizer and add it to the view.
Keep a reference to the recognizer to test in gestureRecognizer:shouldReceiveTouch:.

  1. recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
  2.     [self.view addGestureRecognizer:recognizer];
  3.     self.tapRecognizer = (UITapGestureRecognizer *)recognizer;
  4.     recognizer.delegate = self;
  5.     [recognizer release];

Get direction in handle method:

  1. - (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
  2.     if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
  3.     }
  4. }

In UKit.framework we have few new objects for this:

Source: developer.apple.com