keyboard setInputAccessoryView buttons not firing - iphone

I want to show next previous buttons above the keyboard. I call function "makeToolBars" from viewDidLoad to create it. The application does display the buttons correctly but when I click on them I get error it does not go to "goToNextField" function.
Can anyone point how to correct it ?
-(void)goToNextField:(id)sender
{
[txtPassword resignFirstResponder];
[txtUserName becomeFirstResponder];
}
-(void) makeToolBars
{
UIToolbar *toolbar1 = [[[UIToolbar alloc] init] autorelease];
[toolbar1 setBarStyle:UIBarStyleBlackTranslucent];
[toolbar1 sizeToFit];
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
initWithTitle:#"Next"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(goToNextField)];
UIBarButtonItem *flexButton1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
NSArray *itemsArray1 = [NSArray arrayWithObjects: nextButton,flexButton1, nil];
[flexButton1 release];
[nextButton release];
[toolbar1 setItems:itemsArray1];
[txtUserName setInputAccessoryView:toolbar1];
}

The below statement is wrong.
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
initWithTitle:#"Next"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(goToNextField)];
use the below modified correct code .
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
initWithTitle:#"Next"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(goToNextField:)];
Because you might forget to append colon in goToNextField (Correct goToNextField:).
And in your function implementation for goToNextField you were considering the colon and put :(id) sender in your function.

You've written action:#selector(goToNextField)];. It should be action:#selector(goToNextField:)];

Related

Is it possible to add title to toolbar button, declared as UIBarButtonSystemItem

I'd like to set some buttons in my navigation toolbar and, for users not be confused of what each button do, I'd like to add title to each button, displayed under it. Is it possible to do this?
Declaration of button:
UIBarButtonItem *changeFiltersButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:#selector(refreshButton)] autorelease];
``...
[self setToolbarItems:[NSArray arrayWithObjects: flexible,
changeFiltersButton, flexible, flexible,
refreshFiltersList, flexible, flexible,
more, flexible, nil]];
use images with name like the fallowing example
NSMutableArray *toolBaritems = [[NSMutableArray alloc] init];
[toolBaritems addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];
[toolBaritems addObject:[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"img.png"] style:UIBarButtonItemStylePlain target:self action:#selector(refresh)]];
[toolBaritems addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];
[toolBaritems addObject:[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"img2.png"] style:UIBarButtonItemStylePlain target:self action:#selector(change)]];
[toolbar setItems:toolBaritems animated:NO];

problem with navigation based template

hii every one
i am creating a navigation based application & i am designing screens programatically , i need to have 2 bar buttons ie left barbutton item & right bar button item so i have used following code in - (void)loadView method but its crashing when controller enters loadview method,,can any one tell me whats wrong in this code, thanx in advance
self.title = #"Add Item";
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:#selector(cancel_Clicked:)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:#selector(save_Clicked:)] autorelease];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
Try this code
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:#"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(flipView)];
self.navigationItem.rightBarButtonItem = flipButton;
[flipButton release];
Try following code,
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:#selector(yourfunctionToCall:) forControlEvents:UIControlEventTouchUpInside];
btn.frame=CGRectMake(3, 2, 53, 30);
UIBarButtonItem *btnBack=[[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem=btnBack;
[btnBack release];
[btn release];
same way create for rightBarButtonItem
self.title = #"Add Item";
UIBarButtonItem *cancelbutton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:#selector(cancel_Clicked:)] autorelease];
self.navigationItem.leftBarButtonItem=cancelbutton;
[cancelbutton release];
UIBarButtonItem *savebutton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:#selector(save_Clicked:)] autorelease];
self.navigationItem.rightBarButtonItem=savebutton;
[savebutton release];

UIBarButtonItem is not working

I change the UIBarButtonItem title at run time but it does not work
if(self.toolbarItems!=nil)
{
NSArray *toolbaritem=self.toolbarItems;
UIBarButtonItem* tmpeditButton =[toolbaritem objectAtIndex:0];
tmpeditButton.title=#"Done";
NSLog(#"log %#",tmpeditButton.title);
}
Log is always displays the value of NULL. Why and how to fix that?
Use this
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:nil];

how to set custom method with rightnavagation Button in NavBar

I want set my custom method "Home" with RightNavagation button how should I?
My code
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:#selector(home:)];
[barButton setImage:[UIImage imageNamed:#"home_btn.png"]];
[self.navigationItem setRightBarButtonItem:barButton];
Know I want to link this method with it.
-(IBAction)home{
MainViewController *main=[[MainViewController alloc]
initWithNibName:#"MainViewController" bundle:nil];
[self.navigationController pushViewController:main animated:YES];
}
how should I Do this please help me out.
Try to change
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:#selector(home:)];
in
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:#selector(home)];
compare your selector #selector(home:) with your action -(IBAction)home
See the missing colon in your action?
Change your action to
- (IBAction)home:(id)sender

trying to programmatically create rightBarButtonItem

This doesn't seem to be working. What am i doing wrong?
-(void)awakeFromNib{
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(showNewEventViewController)];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
NSLog(#"awaked");
[rightBarButtonItem release];
}
my guess is, that you add the UIBarButtonItem to the wrong object!
you need to add it, to the rootViewController (instead to the UINavigationController, as you probably did)
YourRootViewController *theRootController = [[YourRootViewController alloc] init];
UINavigationController* navContainer = [[UINavigationController alloc] initWithRootViewController:theRootController];
UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(dismiss)];
theRootController.navigationItem.rightBarButtonItem = btnCancel
[navContainer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:navContainer animated:YES];
I would normally put this code in the viewDidLoad method rather than the awakeFromNib method; I'm not sure if that's where your problem lies. What does "not working" mean?
Try this instead:
- (void) initUI {
UIBarButtonItem *btnCancel = [[[UIBarButtonItem alloc] initWithTitle:#"Cancel"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(dismiss)]autorelease];
self.navigationItem.rightBarButtonItem = btnCancel;
//[btnCancel release]; no need to explicitly release the item
}