iOS how to set FBFriendPickerViewController doneButton's title - facebook

there is a "doneButton" and a "cancelButton" in FBFriendPickerViewController, whose default title is "Done" and "Cancel". I want to customize the title:
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"invite your friend";
friendPickerController.doneButton.title = #"invite";
I think it should work, but it didn't. the title of doneButton was still "Done".
how can i set it? thanks!

This is how you change the title on the Done and Cancel buttons in a FBFriendPickerViewController:
friendPickerController.cancelButton = [[UIBarButtonItem alloc] initWithTitle:#"Skip it!" style:UIBarButtonItemStyleBordered target:self action:nil];
friendPickerController.doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Invite!" style:UIBarButtonItemStyleDone target:self action:nil];

Related

How to make navigation button with Login and Setting title

I want to add two buttons two navigation bar on right hand side one for settings and one for login but problem is that only one button i have searched comes on right that is edit is there any other way in which we can make two button and give them desired title.
UIBarButtonItem *addAttachButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addAttachmentClicked:)];
UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:LS(#"Send") style:UIBarButtonItemStyleBordered target:self action:#selector(sendClicked:)];
self.navigationItem.rightBarButtonItems = #[addAttachButton,sendButton];
Here is the code I am using in My UIViewController's implementation file (.m file)
-(void)viewDidLoad{
[super viewDidLoad];
//back button
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:#" Back " style:UIBarButtonItemStyleBordered target:self action:#selector(backTo:)];
//Optional: if you want to add space between the back & login buttons
UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpaceBarButtonItem.width = 12;
//login button
UIBarButtonItem *signIn_BarButton = [[UIBarButtonItem alloc]initWithTitle:#" SIGN IN " style:UIBarButtonItemStyleBordered target:self action:#selector(signInUser)];
//add all buttons to right side
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:backButton, fixedSpaceBarButtonItem,signIn_BarButton, nil];
}
now here are the metthods for both button clicks
-(IBAction)backTo:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
-(void) signInUser{
//handle your sigin logic here
}
Please! let me if you need more help!

adding a leftBarButtonItem crashes

So I am trying to set my leftBarButtonItem to my navigation item via the following code:
UIBarButtonItem * leftSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
self.navigationItem.hidesBackButton = YES;
leftSpacer.width = 10;
self.navigationItem.leftBarButtonItem = leftSpacer;
However, it gives me a program received SIGABRT. Why is this?
use some of this code that may helps you.
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:#selector(refresh:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
// stick the buttons in the toolbar
[tb setItems:buttons animated:NO];
// and put the toolbar in the nav bar
self.navigationItem.LeftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tb];
Your code sample shows you alloc and init the bar button item, but you show no release. Do you release it? [leftSpacer 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];

Set the position of a UIBarButtonItem Programmatically

How would I be able to set the position of a UIBarButtonItem? Like, I would like to set it to be on either the very right of a UIToolbar or the very left depending on a state.
Thank you.
You do not set directly the position of a UIBarButtonItem in an UIToolbar. Instead you defined the items' order and put flexible space on the left or on the right.
What you can do is:
Create the UIBarButtonItem you want to place (button 1).
Create an UIBarButtonItem of type UIBarButtonSystemItemFlexibleSpace (button 2).
If you want to put the button on the left, create an array with (button 1) and (button 2) and pass it to the UIToolbar by using the setItems:animated: method.
If you want to put the button on the right, create an array with (button 2) and (button 1) and pass it to the UIToolbar by using the setItems:animated: method.
I hope it helps you...
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
[keyboardDoneButtonView sizeToFit];
UIBarButtonItem* PrevButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:105 target:nil action:nil]; //<
UIBarButtonItem* NextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 target:nil action:nil]; //>
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(doneClicked:)];
UIBarButtonItem* flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *fake = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:nil action:nil] ;
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects: PrevButton,fake, NextButton,fake,flexSpace,fake,doneButton,nil] animated:YES];
Link explains Bar Button Item Methods and Arguments
https://developer.apple.com/library..... Use Fake Item to get exact pinch location on Button...

Change text on back button in iPhone SDK

I'm using iPhone SDK 3.1.3 and I tried look like that
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
It's not working and nothing effect. So, I tired
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
button text it change and stye it squre. I click it and it's not go to back.
I want to change back button to text #"Back". How to write it ?
I also read in there but not work for me.
I got it. I change in title and it's OK
self.navigationItem.title =#"Back";
[self.navigationController pushViewController:browser animated:YES];