In application I have root ViewController with login form who checks did user mark "auto login" checkbox and did his last login was successful.
If yes: ViewController proceeds auto login routine and performing push to MainMenuViewController.
If not: the user have to enter his login credentials and hit login button and after login the same segue is performed.
In the case of "manual" login everything works fine, but in the case when autologin is performed I'm getting non functional "back" button (without back arrow) on Navigation bar in MainMenuViewController where it shouldn't appear and after next segue back button is not shown, but it should be. Moreover after going back from next segue (with back swipe gesture) everything is back to normal.
In iOS7 this works just fine.
Excerpt from the code:
In MainMenuViewController I have within viewDidLoad
self.navigationItem.hidesBackButton = YES;
LoginViewController
Login method
...
if([self processLogin:username password:password]){
[self goToMainMenu];
} else {
...
Segue method
-(void)goToMainMenu {
[self performSegueWithIdentifier:#"toMainMenu" sender:self];
}
I think you should solve it by programming in swift or .m file.
For example, By implementing of autologin, You should flag a login status.
that is in goToMainMenu function, you can do it as following.
(void)goToMainMenu()
{
if(flag) {
[self performSegueWithIdentifier:#"toMainMenu" sender:self];
}
else {
[self performSegueWithIdentifier:#"toOtherView" sender:self];
}
}
Related
I am using a blazor sever app
I have a control that when clicked using the #onclick event handler I want to navigate to a new page using the NavigationManager in the click event method.
it doesn't really matter what the control is (button, a, tr, etc) they all have the same behavior
if I put a break point in the HTML I can see the current page is re-rendering before it goes to the new page.
a simple way to reproduce this behavior is to make a new blazor project and in the counter.razor page
change the code to this
#page "/counter"
<h1>Counter</h1>
#if (1 == 1)
{
<p>Current count: #currentCount</p>
}
<button class="btn btn-primary" #onclick="IncrementCount">Click me</button>
#code {
private void IncrementCount()
{
//currentCount++;
}
}
put a break point on the HTML line "#if (1 == 1)"
when the button is clicked it calls the click event which does nothing (code commented out), it then re-renders the page and the break point is hit.
The same happens if I add code in the click event calling navigationManager to navigate away from the page, it re-renders before it leaves the page when nothing has changed on the page.
adding onclick:preventDefault and/or #onclick:stopPropagation does not change this
the only thing I have found that does work is adding
private bool c_blnStopRendering = false;
protected override bool ShouldRender()
{
if (c_blnStopRendering == true) { return false; }
return base.ShouldRender();
}
and setting the c_blnStopRendering = true; in the click event
but this seems like over kill and very manual to add it everywhere it is needed
That's the only way to do it at the moment. There is a request in the backlog https://github.com/dotnet/aspnetcore/issues/18919
I was wondering how you got on with this. I had exactly the same problem (I just wanted to NavigateTo without any re-rendering). Overriding ShouldRender to return false, stopped everything - i.e. it didn't NavigateTo the URL. I was however, Navigating to the same page, but with different parameters in the QS. I seem to have solved the problem, (I think !) when I discovered an optional parameter in the NavigateTo method (public void NavigateTo(string uri, bool forceLoad = false);). I set that to true and it seems to be OK now. Was just interested in your experience
What is the correct way to handle model navigation?
The first case below works as expected but I can then go back to the login page which I don't want. The second case I can see in the debugger that that page is loaded but never shown. Basically the model page stays on top. I am thinking I need to either close the model page before changing pages or I need to handle this differently. I don't won't to pop to root because the root is no longer home but main.
What I really won't to do is change the root, how?
[Edit] This seems to help but there is still a flicker when I unload the modal page.
await _navigator.PushAsync(vm => { vm.NoHistory = true; });
Case 1:
return viewFactory.Resolve<HomeVM>(); - from APP.cs
await _navigator.PushAsync<LoginVM>();
await _navigator.PushAsync<MainVM>();
Case 2:
return viewFactory.Resolve<HomeVM>(); - from APP.cs
await _navigator.PushModalAsync<LoginVM>();
await _navigator.PushAsync<MainVM>(); - Never works.
One way is to reset MainPage completely with the new page when login in successfully.
if (string.IsNullOrEmpty(authLoginToken))
MainPage = new LoginPage();
else
MainPage = new RootPage();
More detailed info, you can take a look the following thread:
https://github.com/asthanarht/CPXamarin/blob/master/CPMobile/CPMobile/App.cs
https://forums.xamarin.com/discussion/48634/from-login-page-to-main-page
i have UiViewController as a LoginPage if it passed then it should show UITabBarController firstTab's ; the first tab inside UINavigationController as RootView.
how can i present firstTab from Login Page; i tried the following but error show :
Code IOS 7 StoryBoard
-(void)successLogin{
HomeTableViewController *vc =[self.storyboard instantiateViewControllerWithIdentifier:#"RootViewInControllerInFirstTabBar"];
[self presentViewController: vc animated:NO completion:nil];
}
i assume that the view that should appear after the login page should have tabs- with the first tab selected. the frst tab should have the home tableVC, which is also the root controller of a navigation controller, displayed.
[Updated]
According to my understanding of the doc, you'll first create the login page.
On successful login, the screen will navigate to a new controller derived from UITabbarViewController. Navigation to the UITabbarViewController depends on your choice, or you can even replace the view on the login screen(entirely your choice). Now on the derivedViewController you will set the viewcontrollers that you want to display on each tab using the following method of the UITabbarViewController.
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
On the first item of the tab bar, you will create a new controller(for profile) which will be the rootviewController of the UINavigationController.
I am trying to change the action executed by pressing the backBarButtonItem of a Navigation Controller.
I know that i have to edit the backBarButtonItem before the next view (on which the button with custom behavior should appear) is pushed. So in the previous ViewController i added the following code, to push via segue:
#pragma mark - segue methods
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"SettingsToProfile"]) {
MyProfileViewController* myprofileVC = [segue destinationViewController];
myprofileVC.myProfile = myProfile;
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Settings_" style:UIBarButtonItemStylePlain target:myprofileVC action:#selector(popTOSettingsViewController:)];
} else {
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStylePlain target:nil action:nil];
}
}
The title "Settings_" gets displayed correctly, but "target: myprofileVC action:#selector(popTOSettingsViewController:)" doesn't seem to have any effect at all.
Background:
MyProfileViewController is a View, where the user can edit his/her own information. Whenever the backbarbutton is clicked, i want to check if something in the GUI has been changed by the user. If thats the case, a UIAlterView should ask the user, if he/she wants to save the changing. I tried to work it out with, viewWillDissappear, but the AlterView gets displayed in the next ViewController (and program crashes, if i click on the alterViewButtons).
I'm not sure that you can change the target of a backBarButtonItem. How about self.navigationItem.leftBarButtonItem instead? There's a discussion at self.navigationItem.backBarButtonItem not working ?? Why is the previous menu still showing as the button? that may be relevant.
We have a tab bar + navigation control project. We have created a tab bar through interface builder and added all tab items to the tab bar controller through through interface builder.
Our application has a login screen which we are showing as a modal form at the beginning. Once the user is authenticated, the login screen is dismissed (using dismissModalScreen) and the MainWindow is shown. This is all working fine.
Now, we have a logout option clicking on which we should show the login screen back. We are able to show that as well. But the issue is once the user is authenticated again, we want all the screens to be loaded freshly. Currently, all screens maintain their state and retain previous data.
What we have tried to do is:
[AppDelegate tabBarController release];
AppDelegate.tabBarController = nil;
We have tried releasing the tabBarController and setting it to nil. But once the view is shown, we are not able to select any of the tabs and the view is blank.
What we need is:
Once the user logs in second time, how to release and reload each viewcontroller which are part of tabbar.
Your help will be greatly appreciated.
We have found a way out. What we are doing now is, once the user logs back in, we are releasing the view controllers and recreating them and setting it back to the uitabbar.
NSMutableArray *arrControllers = [[AppDelegate.tabBarController.viewControllers] mutablecopy];
[arrControllers removeAtIndex:3];
[arrControllers removeAtIndex:2];
----Create New Controllers
UIViewController viewController2 = [[UIViewController alloc] initWithNibName:#"viewController2" bundle:nil] autorelease];
UIViewController viewController3 = [[UIViewController alloc] initWithNibName:#"viewController3" bundle:nil] autorelease];
--Create Nav controller
UINavigationController navViewController2 = [[[UINavigationController alloc] initWithRootViewController:viewController2 ] autorelease];
UINavigationController navViewController3 = [[[UINavigationController alloc] initWithRootViewController:viewController3 ] autorelease];
[arrControllers addObject:navViewController2];
[arrControllers addObject:navViewController3];
[AppDelegate.tabViewController setViewControllers:arrControllers];
It is working fine after this change.
Only problem we faced was if we release all objects from the array, we get a carsh. Is it because, when you release allObjects, the first controller which is the RootViewController is getting released?
Thanks