This is my first post and I'm brand new to iOS programming. I am using xcode 4.3 and have probably a simple question. I examined all the ways to place the toolbar above the keyboard, on which there is a previous / next button. I found a few questions on how to do this when xcode uses an interface builder. But I can not find one that is designed for the latest version of xcode. So I took what I found on the Internet and from the Apple dev site, and came up with some kind of code. The only thing is not working! I get an error message that says about the purpose of the readonly property in the lines with inputAcessoryView. I know that this is probably something simple, but when transferring the code from the previous version to the newer version, I most likely messed up something. Can someone check my code and tell me what I did wrong.Thank. I included .h / .m files
#import <UIKit/UIKit.h>
@interface keyboardViewController : UIViewController
@property (retain, nonatomic) IBOutlet UIView *textField1;
@property (retain, nonatomic) IBOutlet UIView *textField2;
@property (nonatomic, retain) UIToolbar *keyboardToolbar;
-(void)resignKeyboard:(id)sender;
-(void)previousField:(id)sender;
-(void)nextField:(id)sender;
@end
implimentation
#import "keyboardViewController.h"
@interface keyboardViewController ()
@end
@implementation keyboardViewController
@synthesize textField1;
@synthesize textField2;
@synthesize keyboardToolbar;
- (void)viewDidLoad
{
[super viewDidLoad];
if (keyboardToolbar == nil)
{
keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
UIBarButtonItem *previousButton = [[UIBarButtonItem alloc] initWithTitle:@"previous"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(previousField:)];
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"next"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(nextField:)];
UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFlexibleSpace) target:nil action:nil];
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemDone) target:self action:@selector(resignKeyboard:)];
[keyboardToolbar setItems:[[NSArray alloc] initWithObjects:previousButton, nextButton, extraSpace, done, nil]];
textField1.inputAccessoryView = keyboardToolbar;
textField2.inputAccessoryView = keyboardToolbar;
}
}
-(void) resignKeyboard:(id)sender
{
if ([textField1 isFirstResponder])
[textField1 resignFirstResponder];
else if ([textField2 isFirstResponder])
[textField2 resignFirstResponder];
}
-(void) previousField:(id)sender
{
if ([textField1 isFirstResponder])
[textField2 becomeFirstResponder];
else if ([textField2 isFirstResponder])
[textField1 becomeFirstResponder];
}
-(void) nextField:(id)sender
{
if ([textField1 isFirstResponder])
[textField2 becomeFirstResponder];
else if ([textField2 isFirstResponder])
[textField1 becomeFirstResponder];
}
- (void)viewDidUnload
{
[self setTextField1:nil];
[self setTextField2:nil];
[self setKeyboardToolbar:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end