How to set in Android to be navigated to the same fragment every time from the bottom navigation bar? - android-fragments

I have 4 fragments: A, B, C and X.
A, B and C are found on the bottom navigation bar, so every time I click on item A, I get the A fragment on the screen, click on B, I get B.
When I click on C, I get the C fragment, which has a button, that takes me to X fragment.
Now my problem is, that if I click on the Navigate to X button, after that when I navigate to anywhere from there and then back again on C, I get X.
But everytime I click on the item C, I want to get back to fragment C, no matter if I got to the X fragment before that.
How can I implement this?

I found the answer, I needed to pop the X fragment off the stack, with adding this to the action tag navigating to it:
app:popUpTo='nav_graph_id'
and
app:popUpToInclusive="true"

Related

How can I get mouse coordinates in Blazor Web Assembly

I create a generic grid component, in the last column, I put an icon with dots that should open the edit menu for every row, like this...
How can I calculate mouse coordinates to open the edit window near clicked row edit icon??
On the edit window I need to show the Edit, Delete, Move buttons.

two different custom transitions in a navigationController

I'm trying to make two different custom transition (one fade and one slide from top) within a navigation controller.
The transition works very well the first time but when pop the transitions acting crazy.
I guess that navigationController.delegate is the key but I can't figure it out by myself.
Any help will be greatly appreciated
thanks a lot
******************************** IOS14 QUESTION UPDATE *****************************************
the solution of #Vlad for setting the delegate is working great thanks.
But recently in IOS14 a stack menu appearing when a long press gesture is detected on navigation back button (which allows user to navigate through the navigationcontroller's viewcontrollers stack).
And so the navigationcontroller delegate is setting to the wrong controller when popping two or more controllers.
I am once again asking for your support
Your starting state is in VC A.
After viewDidLoad, the navigationController?.delegate is set to VC A which uses anim1.
When you push to B, you're setting navigationController?.delegate to B, which uses anim2.
When you pop from C to B, anim2 is used as navigationController?.delegate is VC B.
When you pop from B to A, anim2 is used because navigationController?.delegate is still VC B.
When you pop B, navigationController?.delegate is set to nil because the instance of VC B is destroyed.
That is why when you try and push B again, the default animation is used.
Two important pieces of information is that:
viewDidLoad is only called one time when the view has finished loading and not when it appears again after a pop.
navigationController?.delegate can only point to one delegate.

Close all ContextMenu with mouse button

Is there a way to close all opened context menus opened on the scene?
When I press a button I would like to close all Context menus opened by right muse click.
Sure, just have some data structure, say a Stack<ContextMenu> Where every time you make a context menu, you push it on the stack, and every time you hide it, you pop it off the stack. Then when you press a certain button, just iterate through the stack and call the .hide() method of contextMenu, on each item i the stack, hiding them as you go, and voila! that should do it.

XCode - Navigation Controller Push Segue - Pass Data between Views and Skip Navigation Sequence

I have 2 questions about this storyboard test project. I am new to Xcode, and I can't find solution to this problem.
This is Storyboard setup
View Controller A is Root View Controller. View B and View C extend from it separetely. Table View extends from View C. View B has 2 buttons - To Table View and to View B.
(I forgot to add textField on View B, and segue from B to A)
1) Button To Table View pushes Table View. Table Cell contains a string. Pressing the cell, view goes back to View Controller C and that string is displayed in text Field.
problem 1: if I use modal segue from table view to view C textField will be updated with method prepareForSegue, but I will lose Navigation Bar on view C.
problem 2: if I use push segue from table View to View C, back button on view C will not point to view A, it will point to table View.
Solution?
Click on the text field to select it, then press back button to update view C. But how to implement?
Or is there better solution?
2) I want to press button on View C to go to view B. If I use push segue, View B Back button will point to view C. If I use modal push, view B loses Navigation bar.
Can I somehow make push segue to View B, that it's back button points to view A?
[EDIT]
to pass data between view Controllers, I used NSUserDefaults. Turns out that it is very efficient way of passing simple data (strings, numbers, etc) between Views
hot to use it for MODAL segue? in desired tableViewController add in the
-(void)tableview:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//define user defaults
NSUserDefaults *defaults = [NSUserDefaults standardDefaults];
NSString *testString = #"test";
[defaults setObject:testString] forKey:#"test1"];
[defaults synchronize];
//dismiss ViewController
[self dismissViewControllerAnimated:YES completion:nil]; }
if you wish to use push segue to dismiss view controller and skip navigation sequence (drop the view from sequence) replace
[self dismissViewControllerAnimated:YES completion:nil];
with
[self.navigationController popViewControllerAnimated:YES];
I will update this answer as we get through each problem.
If you are using the table view as a means to make a selection then you should instead Dismiss the table view controller instead of pushing a new view modally.
//In the table view controller's on cell selected method
[self dismissViewControllerAnimated:YES completion:^{
//code
}];
Pushing views will result in the the next view being placed on top if you want to get back to view A from view C (Provided you presented it modally) you can use the same code above to get back from C to A
Basically in this case:
View A --modal-> View C --modal-> TableViewController
Then you have to call the above code once in TableViewController and once again in ViewController C
and bam back to A
As far as having B point back to A it's easier if you go from A to B However if you never really need to go from A to B I suggest changing up the structure.
But to fulfill your request one method of switching your view hierarchy is by dismissing view C while at the same time pushing B on top of A.
//Inside View C If you want it to happen only after the first animation completes just move the other line up into the block
[self dismissViewControllerAnimated:YES completion:^{
//code
}];
[self.parentViewController.navigationController pushViewController:<#(UIViewController *)#> animated:YES];
I hope this is helpful.

iPad - Show viewcontroller as subview from displayed modal view controller

The current structure of an ipad app im working on is like so - In a navigation based application's view controller I have a tableview on the left side of the view and an IBOutlet connected uiview say View A on the right side (screen is divided in these 2 parts, much like a splitview controller). Clicking any row of the left table adds as subview, a uitableviewcontroller view say View A1 inside View A. Clicking any row in A1 brings up a modalview, say View B. View B now has buttons to bring up another view uitableviewcontroller say View A2. Now the way to bring up View A2 like as per the need, i need to first dismiss the modal View B and show the View A2 added as a subview on top of View A1 but with a back button. Hitting this back now should show the previously dismissed modal uiviewcontroller B, which on dismissing reveals View A1. Now I've managed to get everything working up to the point of showing modal View B, but im out of ideas how to proceed with the rest of the flow. Basic steps i need to put together would be,
Dismiss B
Show A2 over A1
Clicked 'back' in A2
Remove A2 & show B
Dismissed B, show A1.
Any suggestions/ ideas/ code to do this?
I figured it quite a while ago but realised i never updated the answer here. So for anyone else who may have a similar implementation, the way i did it was to save a reference to the modal viewcontroller B in the viewcontroller A1, using it to show & dismiss B. Next was fairly simply to do some delegation to tell A1 when to display A2 and on dismissing A2, to tell A1 to show up the modal viewcontroller B. Took a while to do this but it worked like I wanted. HTH.

Resources