Skip to content

How to Use

lrossetti edited this page Jun 1, 2013 · 3 revisions

How to Use

Currently it only works with the UITextField object.

If you are developing in an ARC project add the following flag in the build files: -fno-objc-arc

Step by step

The usage is pretty simple:

  1. Initialize the UIAccessoryView object
  2. Set both datasource and delegate properties to your ViewController
  3. Set the view as the fields InputAccessoryView with the field method setInputAccessoryView
  4. Use an array to store all your fields
  5. Call the method UIAccessoryView reloadData
  6. Done!

It uses delegate methods, the same way UITableView does it.

Include the files UIAccessoryView.h and UIAccessoryView.m in your xcode project.

Detailed usage

Then you should include the header file: #import "UIAccessoryView.h"

Initialize the controller as bellow:

UIAccessoryView *v = [[UIAccessoryView alloc] init]; v.delegate = self; v.dataSource = self;

[field1 setInputAccessoryView:v]; [field2 setInputAccessoryView:v]; [field3 setInputAccessoryView:v];

dataSource = [[NSMutableArray alloc] init]; [dataSource addObject:field1]; [dataSource addObject:field2]; [dataSource addObject:field3]; [v reloadData];

Bellow are the delegate methods:

  • (void) didPressedDoneButton { [_field resignFirstResponder]; }

  • (NSInteger) numberOfFields { return [dataSource count]; }

  • (UITextField *)fieldForRowAtIndex:(int)index { UITextField *f = [dataSource objectAtIndex:index];

    return f; }

Done!

You can also open the xcode project and check the files RooViewController.h and RooViewController.m for a practical example.

Clone this wiki locally