Create a custom UIView
that defines the common input accessory view. Should include a definition of a delegate to allow the class using the accessory view to handle, for example, previous/next button taps as appropriate. Here's a header file example for a keyboard accessory view:
#import <UIKit/UIKit.h>
@class KeyboardAccessoryView;
@protocol KeyboardAccessoryViewDelegate <NSObject>
-(void)accessoryNext:(id)sender;
-(void)accessoryPrevious:(id)sender;
@end
@interface InputAccessoryView : UIView
@property (nonatomic, weak) id<KeyboardAccessoryViewDelegate> delegate;
@property (nonatomic, setter = enablePrevious:) BOOL previousEnabled;
@property (nonatomic, setter = enableNext:) BOOL nextEnabled;
-(id)initPreviousNextAccessory;
@end
Edit - showing details of use in a UIViewController
.
The .h file:
#import <UIKit/UIKit.h>
#import "KeyboardAccessoryView.h"
@interface MyViewController : UIViewController <KeyboardAccessoryViewDelegate>
//...
@end
The .m file:
#import "MyViewController.h"
@interface MyViewController () {
KeyboardAccessoryView *inputAccessoryView;
}
@end
@implementation MyViewController
//...
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
inputAccessoryView = [[KeyboardAccessoryView alloc] initPreviousNextAccessory];
inputAccessoryView.delegate = self;
//...
}
-(void)accessoryNext:(id)sender{
// handle Next
}
-(void)accessoryPrevious:(id)sender{
// handle Previous
}
//...
@end