Instagram cancel button - ios

I am using a webView to show Instagram login. However there is no cancel button. How do I add a cancel button? I tried to add a cancel button on top of the webView but it's not relative to the webView, in that if you were to drag down that window as if to refresh it,the cancel button will remain static. Is it possible to have it right next to the Log in button? If not is the uINavigationBar the best way?

If all you want from the cancel button is to close the webView, you can have the webView embedded in a UIViewController which is added to the UINavigationController stack. Then you will be able to add the Cancel Button as a UIBarButtonItem on the navigation bar.
For example:
Your home screen is MainViewController and you tap a button to show Instagram in webView. Then in your MainViewController.m (which is already the rootViewController of the UINavigationController) do this:
// Init your web view controller and push to UINavigationController stack to show it.
WebViewController *yourWebViewContainer = [self.storyboard instantiateViewControllerWithIdentifier:#"YourControllerIdentifier"];
[self.navigationController pushViewController:yourWebViewContainer animated:YES];
Then in your WebViewController.m file, create the cancel button in viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStylePlain target:self action:#selector(cancelTapped:)];
}

You can't add the cancel button beside the Login button because it's in web view which contains html code, but you can add button on navigation bar using this code:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStylePlain target:self action:#selector(cancelAction:)];
self.navigationItem.rightBarButtonItem = cancelButton;
}
-(void)cancelAction:(UIButton *)sender{
//do cancel action
}

Related

Trying to handle the leftBarButton in UINavigationBar

My UINavigationBar is not handling properly.
I would like it to Navigate back to the last UIViewController, though i get a black screen when pressing the leftBAckButton and not the previous UIViewcontroller.
View
Controller.m viewDidLoad
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:#"&" style:UIBarButtonItemStyleBordered target:self action:#selector(home:)];
self.navigationItem.leftBarButtonItem = newBackButton;
This is the -(void)home:(UIBarButtonItem *)sender
-(void)home:(UIBarButtonItem *)sender {
[self.navigationController popToRootViewControllerAnimated:YES];
}
Though i feel this is correct i receive this when pressing the button
As you can see the navigationbar seems to disappear and it never navigates to the previous view controller.
When using [self.navigationController popViewControllerAnimated:YES];
I receive! this on the UI
What is causing this and how can i fix it?

My Custom UINavigationController won't show right button

I have a "LoginViewController" which presents a new Controller which is a subclass of UINavigationcontroller when clicking a button:
MPNavigationViewController *controller = [[MPNavigationViewController alloc] initWithRootViewController:[[MPQuestionFirstViewController alloc] init]];
[self presentViewController: controller animated:YES completion:nil];
"MPNavigationViewController" subclass UINavigationController and uses "REMenu" to have a sliding-from-top menu ("Link") and on viewDidLoad I try to add a right button to open it:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *toggleMenuButton = [[UIBarButtonItem alloc] initWithTitle:#"Show" style:UIBarButtonItemStylePlain target:self action:#selector(toggleMenu:)];
self.navigationItem.rightBarButtonItem = toggleMenuButton;
[self initMenu];
}
It doesn't show any button on the navigation bar. Why could it be?
If I try to add the button from one of the "viewControllers" that will handle sections on the menu. It shows the button, but it doesn't paint it at all.
Thanks.
You are using subclass of UINavigationcontroller which is not actually view controller.
There is only one solution, You need to create your custom button and add it to UINavigationbar as a subview..
Use this hope it will help.
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(goToDoneButtonAction)];
self.navigationItem.rightBarButtonItem = doneButton;

iPhone - Add "Add" Button when Edit button is selected in UITableView

i have a table view in my application which shows some items. when i click on one item, a new table view appears (with navigation controller: push). So at the top of the Table view there is now the navigationcontroller with the automatic "back" arrow to get back. i have the "edit" button enabled on the right side.
Now i want when i tap on the edit button, the Back button should disappear and a "+" add button should be there instead of the back button. Is this possible?
Or it is possible to get the Edit and Add button on the screen at the same time?
thanks
This is easy enough. Override the setEditing:animated: method of your view controller. This is called when the Edit/Done button is toggled (assuming you are using the standard editButtonItem from UIViewController).
In this method you create an "add" button and make it the left bar button item. This will hide the back button. Remove the "add" button and the back button will reappear.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (editing) {
// Add the + button
UIBarButtonItem *addBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addAction:)];
self.navigationItem.leftBarButtonItem = addBtn;
} else {
// remove the + button
self.navigationItem.leftBarButtonItem = nil;
}
}
Yep, this is the approach that I used:
Have a property for both the back button and the add button and set it in viewDidLoad:
self.backButton = self.navigationItem.leftBarButtonItem;
self.addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addPressed:)];
Now you just have to swap the buttons and update the TableView state accordingly when 'Edit' is pressed. Here i also change the 'Edit' button to 'Done':
- (IBAction)editBarButtonPressed:(UIBarButtonItem *)sender {
if (self.tableView.editing == NO) {
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(editBarButtonPressed:)];
self.navigationItem.rightBarButtonItem = myButton;
[self.tableView setEditing:YES animated:YES];
[self.navigationItem setLeftBarButtonItem:self.addButton animated:YES];
} else {
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(editBarButtonPressed:)];
self.navigationItem.rightBarButtonItem = myButton;
[self.tableView setEditing:NO animated:YES];
[self.navigationItem setLeftBarButtonItem:self.backButton animated:NO];
}
}
Hope this answers your question. :)
br denrase
The back arrow button is your navigation controller button. So if you want to disappear the same button then you have to write this code below:-
self.navigationItem.hidesBackButton=YES;
Now if you want to add your custom button on the navigation controller then use below code:-
UIBarButtonItem *customButton =
[[UIBarButtonItem alloc]
initWithTitle:#"Add"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(yourMethod:)];
self.navigationItem.rightBarButtonItem = customButton;
You can programmatically hide the back button when your table view begins editing, and then add the "Add" button to the left of your navigation bar.
[self.navigationItem setHidesBackButton:YES];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addButtonPressed)];
[self.navigationItem setLeftBarButtonItem:addButton];
Then, when the user presses Done, replace the "Add" button with the Back button:
[self.navigationItem setHidesBackButton:NO];
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;

Back button not made on navigation bar

I started out with a navigation based project and am pushing further views onto the controller. The problem is that if I do not give a title to the navigation item then the back button is not drawn! Only if I give the navigation bar a title, will the back button come. It seems apple could'nt write "back" or "go back" in case of NO title. I do not want to give the navigation item a title(I'll use a label inside my view). So how do I fix this?
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = #"Home"; /// <- without setting the title, the back button won't show !
}
In the view didLoad method, if I remove the title, the back button won't show
Just create the back button yourself:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:back];
[back release];
}
(If you prefer dot notation, self.navigationItem.backBarButtonItem = back;)

Adding a UIBarButtonItem programmatically to UINavigationBar

I dropped in a UINavigationBar in UIInterfaceBuilder. I present this view modally and just want a UIBackBarButton to return to my last view. I have an outlet and property to this UINavigationBar declared. I thought in my viewDidLoad method, I could create a UIBackButton like this:
UIBarButtonItem *backButton =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleBordered
target:self
action:#selector(goBack)];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
But I do not see my UIBackBarButtonItem on the UINavigationBar. I think I am doing something wrong here since I don't think my UINavigationBar knows I'm trying to add this UIBackBarButtonItem to it in this way. Would I have to do create an NSArray, put the button in it, and setItems for the NavigationBar instead?
I'm confused on how the navigationItem property works vs the setItems of the UINavigationBar as well. Any help would be appreciated. Thanks!
You are trying to set the Back Button Item in a modal view which doesn't add a backBarButtonItem. This what causes the Button (or any sort of back button for that matter) not to show. The backBarButtonItem is mainly for use with Pushed View Controllers which have a Back Button added from the parent (next item below) when you push a new view controller (top item). The Apple UINavigationItem Documentation says:
When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The target and action of the back bar button item you set should be nil. The default value is a bar button item displaying the navigation item’s title.
To get the Back Button on the left side like you wish, Try changing
self.navigationItem.backBarButtonItem = backButton;
to
self.navigationItem.leftBarButtonItem = backButton;
making a call such as this from a view controller
{
NextViewController* vcRootView = [[NextViewController alloc] initWithNibName:#"NextView" bundle:[NSBundle mainBundle]];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vcRootView];
[vcRootView release];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
}
will present NextViewController as a Modal view on the calling view and NextViewController will have a navigationController for it.
In The NextViewController implementation file all you need is this
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self
action:#selector(barButtonBackPressed:)];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];
}
-(void)barButtonBackPressed:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
to have the back button to dismiss the modalview. Hope it helps.
Use below code snippet :
//Add button to NavigationController
UIBarButtonItem *backButton =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#“back”, #"")
style:UIBarButtonItemStylePlain
target:self
action:#selector(goBack)];
self.navigationItem.leftBarButtonItem = backButton;
//Perform action on back Button
- (void) goBack { // Go back task over-here
}
Different style types available are :
UIBarButtonItemStylePlain, UIBarButtonItemStyleBordered, UIBarButtonItemStyleDone
You may use this setters without creation new UIBarButtonItem:
[self.navigationItem.leftBarButtonItem setAction:#selector(doBackButton:)];
[self.navigationItem.leftBarButtonItem setTarget:self];

Resources