Another user provided me with the following code in order to make a mini toolbar above the keyboard when a user is typing in a specific TextView. All I need is a little "close" button to minimize the keyboard when the user is finished, so he/she can continue manipulating the app.
-(void)viewDidLoad
{
[super viewDidLoad]
UIToolbar *inputAccessoryView = [[UIToolbar alloc]init]; // Create one input accessory view, tool bar will be easy for you
inputAccessoryView.frame = CGRectMake(0,self.view.frame.size.height - 44, self.view.frame.size.width, 44);
// Add required buttons
UIBarButtonItem *fontItem = [[UIBarButtonItem alloc] initWithTitle:@"Font"
style:UIBarButtonItemStyleBordered
target:self action:@selector(changeFont:)];
UIBarButtonItem *removeItem = [[UIBarButtonItem alloc] initWithTitle:@"Remove"
style:UIBarButtonItemStyleBordered
target:self action:@selector(removeTextView:)];
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone
target:self action:@selector(dismissKeyBoard:)];
NSArray *items = [NSArray arrayWithObjects:fontItem,removeItem,flexItem,doneItem, nil];
[inputAccessoryView setItems:items animated:YES];
//You should create an outlet for the text view before doing this
[self.questionsTextView setInputAccessoryView:inputAccessoryView];
}
However, the app crashes whenever the "close" button is pressed. I'm not sure if I am following the direction correctly: I am supposed to make an outlet for the TextView, so I made the output to the viewController's header file and named it questionsTextView. Then I synthesized it in my .m file, and named the instance _questionsTextView.
Can anyone please give me hand? I'm brand-new to xcode and am slowly getting the hang of objective-c! Thanks.
the error message you supplied suggest there something wrong with your methods.
double check the all three methods take a parameter as : symbol specify it should, and also check your method spelling.
verify object can respond to method:
NSLog(@"Method does respond: %d", [self respondsToSelector:@selector(aMethod)]);