i have a problem in my app. in an tabbarcontroller i have a login view where i can enter a website. if the login data is correct the view switches to another view. works fine.
now my problem is, when i switch the tab and enter the login view tag again and try to login again, the view does not load.
Whats here the problem? should i dismissmodalviewcontroller when the view is unload or something else???
thanks for help,
brush51
EDIT1:
hi robin, in my login view is an button which calls a webview whit this code:
ShopWebViewController *shopWVC = [[ShopWebViewController alloc] initWithNibName:#"ShopWebViewController" bundle:nil];
shopWVC = [[ShopWebViewController alloc] initWithNibName:#"ShopWebViewController" bundle:nil];
shopWVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[logView presentModalViewController:shopWVC animated:YES];
And now when i exit the tabbar item where this logview is and enter it again, then the first view appears and the login/presentmodalviewcontroller doesnt work again.
cause of this i think that i may have to dismissmodalviewcontroller but dont know if this is right or not.
When you hit the login button:
ShopWebViewController *shopWVC = [[ShopWebViewController alloc] initWithNibName:#"ShopWebViewController" bundle:nil];
shopWVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:shopWVC animated:YES];
[shopWVC release];
Then in your view controller that has just been presented modally, somewhere in your code (perhaps when login is successful?) you need to dismiss it with
[[self parentViewController] dismissModalViewControllerAnimated:YES];
Related
I have UIModalPresentationFormSheet views appearing in my app. Some of them appear from the Right some from the Bottom and the dismissing seems random. Some disappear to the Bottom some go Left some go Up. Is there a way to set the direction they appear from and dismiss to?
Code I use to present (this same code, just different viewcontroller being presented, called from the same view controller has varying animations for different modal views):
MyViewController *newModalView = [[MyViewController alloc] init];
newModalView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:newModalView animated:YES];
Then in the modal view I call this to dismiss it:
[self dismissModalViewControllerAnimated:YES];
This is a known bug and is being worked on by apple.
Try something like this:
newModalView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
All the transition Styles:
newModalView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
newModalView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
newModalView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
I am Making a word game and I need some help with the navigation. This game starts in a menu, from that menu you can click 'create game' which would open the 'GameViewController'. in this GameViewController you can submit a word when it's the right word There Pop ups a screen which is 'RightWordViewController' When it's wrong it pop ups 'WrongwordViewController' in both right and wrong there is a button which would go back to the game.
In the GameViewController there is also a menu button which works perfectly except for after you have submitted a word. If you would click the menu button in a GameViewController when you already had submitted a right or wrong word the menu button would bring me back to the right or wrong view controller. I Understand why this is happening,I just don't know how to fix it. I use dismissModalViewcontroller which shows me the view behind the current, and that is Right or Wrong Viewcontroller I need to fix this and hope someone can help me.
To go from menu to game
-(IBAction)switchview:(id)sender {
GameViewController *game = [[GameViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:game animated:YES];
the menu button that goes from the GameViewcontroller to the main view (menu) (it dismiss the current screen so when I have submitted a word right or wrong those screens pop up and when I would click this button right or wrong would show up again.. what I don't want ofc.)
-(IBAction)switchback:(id)sender {[self dismissModalViewControllerAnimated:YES];
to go either right or wrong I use:
if ([labelsText.text isEqualToString: textview.text]){
RightWordViewController *Rightword = [[RightWordViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:RightWord animated:YES];
}
else
{ WrongWordViewController *Wrongword = [[WrongWordViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:WrongWord animated:YES];
}
And then for Going back to the game screen when Im in Right or Wrong view controller
-(IBAction)switchback3:(id)sender {
GameViewController *game = [[GameViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:game animated:YES];
I hope someone can give me some really clear explanation or some sample code.
In the switchback3: method you don't need to preset the viewcontroller again.. just dismiss the one thats in the front..
[self dismissModalViewControllerAnimated:YES];
also, add a boolean in gameview controller to set a status to check whether to show/not show the right/wrong view.
Use
-(IBAction)switchback3:(id)sender {
[self dismissModalViewControllerAnimated:YES];
Reset your submitted words before presenting the right/wrong view controller.If you are presenting a view and u need to go back,use dismissModalViewController.No need to present that view again.
In my app i have a login screen which i present modally on startup. After a successful login, the user gets redirected to a UITabBarController which has five UINavigationController (for the tabs).
On one tab, i have a button "logout", so that the user gets redirected back to the login screen.
That´s working fine.
But what i want to do is to load the UITabBarController every time the user logs in. That means, that the UITabBarController should NOT be reused. For now, the content in the tabs (i load data from web) stays the same, also when a new login has been done.
How can i release/pop/nil the UITabBarController with it´s UINavigationcontrollers?
What i have tried so far:
Thats the point where i push the user back to the login screen when he presses the "logout" button:
[self.navigationController presentModalViewController:navigContrLogin animated:YES];
[[self navigationController] popToRootViewControllerAnimated:YES]; --> NOT WORKING
[self.navigationController popViewControllerAnimated:NO]; --> NOT WORKING
[self.tabBarController release]; ---> NOT WORKING
Can anybody help me please?
EDIT:
That´s how i add the UITabBarController. I do this when the user clicks the Login Button:
[self.navigationController dismissModalViewControllerAnimated:NO];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:tabBarController animated:NO];
[self.navigationController removeFromParentViewController];
EDIT2: I solved it. What i´m doing is when the user clicks the logout button, i call the navigation controller from the app delegate and use it to push the login viewcontroller.
MyAppDelegate *del = (MyAppDelegate*)[UIApplication sharedApplication].delegate;
[del.navControllerLogin pushViewController:loginController animated:YES];
Have you tried to remove it from the superview and then release it? And then add new ViewControllers?
for (UIView *view in self.window.subviews){
if (view == tabBarController.view) {
[view removeFromSuperview];
}
}
[tabBarController release];
UITabBarController *newTabBarController = [[UITabBarController alloc] init];
newTabBarController.viewControllers = nil; //ADD NEW VIEWCONTROLLERS
[self.window addSubview:newTabBarController.view];
i wouldn't do it with this way. Because managing (release/nil) a parent view from its subview is not a good practice.
init and show tabbar controller after app launch.
if user is not logged on, present loginviewcontroller. if already logged on no need.
after successfull login post a notification and capture it required places.
if user taps on logout, clear user credentials, user related data and present loginviewcontroller again.
I'd add and remove both the modal view controller and tabbarcontroller from the appDelegate.
[myAppDelegate addLoginViewController];
[myAppDelegate removeLoginViewController];
[myAppDelegate addTabBarController];
[myAppDelegate removeTabBarController];
I have the following code in application didFinishLaunchingWithOptions where I want to present a modal view controller for user login.
LoginViewController_iPhone *loginViewController=[[LoginViewController_iPhone alloc]initWithNibName:#"LoginViewController_iPhone" bundle:nil];
UINavigationController *loginNavigationController=[[UINavigationController alloc]initWithRootViewController:loginViewController];
loginNavigationController.modalPresentationStyle=UIModalPresentationFullScreen;
[self.window.rootViewController presentModalViewController:loginNavigationController animated:NO];
[loginViewController release];
[loginNavigationController release];
However, all I get is a blank white screen. If I substitute the following
self.window.rootViewController=loginNavigationController;
the login screen displays correctly. There is no other view controller assigned to the rootViewController property as the app is just starting. Do I need another view controller assigned to get this to work?
Yes. you need to assign something to the window's rootViewController property in order to call its method presentModalViewController.
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:LoginViewController];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:NO];
You can set this up in the viewDidLoad of the view that would load up first as soon as the app starts. So, as soon as login is successful, you can pop it off, and you will have the loaded view ready.
Greetings guys,
I am a newbie in iphone programming. Basically my problem is the following:
I have a view which have inside an info button and a UIScrollView and inside this scrollview I have programatically added buttons with images.
When I press the info button the next view shows up, however when I press a button from scrollview nothing happens knowing that it is catching the click and it is accessing the function that is responsible for showing the next view.
- (void)showFlipid)sender{
FlipsideViewController *controller = initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
NSlog(#"1"); // IT IS SHOWING WHEN I PRESS A BUTTON FROM UISCRoll
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
}
Please help
It seems that your code is missing critical line.
Try to add :
[self presentModalViewController:navigation animated:YES];
at the end of your code.
BTW
you should release the controller at the end.