hii every one
i have created a test project with tab view controller, on click of a tab it will goto that coresponding screen(say screen A) when i click back button in screen A it will come back to main page but with out tabView,
following is may code for back button where DataEntry is a class name to where i am navigating
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithNibName:nil bundle:nil];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
//avController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:addNavigationController animated:YES];
insted of the above code if i use following code
[self.navigationController dismissModalViewControllerAnimated:YES];
it will work fine & ill get back to main page with tabs , but it wont run the updated code which is in the viewDidLoad so i need to navigate to the main page insted of using dismissModalViewController
can any one tell me how can i get tabView when i navigate to the main page with out using dismissModalViewController
this is not correct:
[self.navigationController presentModalViewController:addNavigationController animated:YES];
(this is not what you mean to have: it will present a modal view, when you dismiss it, it will uncover what was below, i.e. your tab)
you should use pushViewController to show your avController so that the back button is activated and so on.
look at this.
I'm struggling a little to understand your problem, but viewDidLoad only runs when the view loads: not when you come back to screen A : its still loaded then. To run code each time screen A is displayed, take a look at viewWillAppear / viewDidAppear http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
I tend to create tabs programatically rather than using the IB: its clearer whats going on. Take a look at this answer to show how I do it.
UITabBar with UINavigationController in code
Related
I have two ViewControllers one named ViewController and another named Signup,
Here is the code I use to call the Signup.xib file,
- (IBAction)signupButton:(id)sender {
Signup *myView = [[Signup alloc] initWithNibName:#"Signup" bundle:nil];
[self.view addSubview:myView.view];
}
This code works. It starts up the Signup Viewcontroller but When I try to call the ViewController.xib file from the Signup.m It doesn't work.
Here is how I call the ViewController.xib file from the Signup.m file,
- (IBAction)loginView:(id)sender {
ViewController *dashboardView = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.view addSubview:dashboardView.view];
}
I have imported the ViewController.h file within the Signup.m file.
The loginView button works because I placed an NSLog() in the button to see if it worked and it does. But When I click the loginView button I get some type of error. I don't know what errors are in xcode but its something like this,
0x110309b: movl 8(%edx), %edi <- Thread 1: EXc_BAD_ACCESS (code=1, address=0x60000008)
It is highlighted in green and I don't know what it means.
As user Priyatham51 said, number 3 is the reason why you are getting the error. The alternative, IF you are not using UINavigationController to push/pop views, is to to present the Signup view controller as a modal view. Then when you want to go back, you can call inside the Signup controller.
[self dismissModalViewControllerAnimated:YES];
However you need to change your signup button to.
- (IBAction)signupButton:(id)sender {
Signup *myView = [[Signup alloc] initWithNibName:#"Signup" bundle:nil];
[myView setModalPresentationStyle:UIModalPresentationFormSheet]; //you can change the way it is presented
[myView setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; //you can change the animation
[self presentModalViewController:myView animated:YES]; //show the modal view
}
I hope this helps you.
Try this to present Signup view to user :
- (IBAction)signupButton:(id)sender {
Signup *myView = [[Signup alloc] initWithNibName:#"Signup" bundle:nil];
[self presentModalViewController:myView animated:YES];
}
And back to Login view by dismissing the signup view controller
- (IBAction)loginView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
You don't generally add View Controller's views to your current view, but if it is what you want to achieve then try cleaning project first. Sometimes XCode fails to properly load nib files after you add/remove them. Go to Product menu-> "Clean", then hold down "Option" key, go to Product Menu and press "Clean Build Folder".
Also, add "All Exceptions" breakpoint. It will be on the left side panel of XCode, under tab "Breakpoints". On that tab there is "+" button at the bottom. Click "Add Exception Breakpoint" and then just press "Done". This basically will give you more information about your crash.
I know that this doesn't exactly help to fix your problem, but will give you more details on it.
The main reason why your code is not working because you are trying to add your ParentView to the subview as a child again and you are not supposed to do that.
It seems like your are trying to do this.
You created your LoginView
You created your SignupView and added it as subview to LoginView. So the LoginView is parent and signup is child.
(Here is your mistake ). You are trying to add the LoginView as the subview of the SignupView. Which is never going to work.
Try doing this
I would suggest you create your LoginView first and have button "SignUp". So when a user clicks on signup "Push" the new SignupView Controller on top the loginViewController. And have a button "Login View" on your signup view . When user click on that button try to "dismiss current view controller". So user will be shown the login view again. You can use this as work around.
Please take a look at this example
http://www.roseindia.net/tutorial/iphone/examples/pushView.html
Here one more working example
http://www.theappcodeblog.com/2011/08/15/iphone-development-tutorial-present-modal-view/
I'm starting my first application for iphone. I'm using xcode 4.3.3, IOS 5, and the principle of storyboard.
the home screen of the application is a tab bar controller and I want to display a login before the home screen if the user does not logged.
I can not find a solution: if I have to use the file AppDelegate.m with the function didFinishLaunchingWithOptions() or file of my controller with the function viewDidAppear() or something else.
if someone would help me for a solution
Thank you.
just create the login screen when your app is launched and when your login is succeed push your tab bar controller from there...
It is better to add function in AppDelegate.m to remove unwanted window appearing if not logged in (Your home view will be shown for a moment before redirecting to login page if you write code in ViewDidAppear method).
Another method is add a new view controller and check where to redirect based on log in status from view controller's ViewDidAppear method.
Try using a Modal View Controller, Docs
On didFinishLaunchingWithOptions() or viewWillAppear() try do something like this:
YourViewController *viewController = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
viewController.modalPresentationStyle = UIModalPresentationFormSheet;
//Present as Model view controller
["presentedViewController" presentModalViewController:viewController animated:YES];
//release it After presenting to it
[viewController release];
Then to remove it call: dismissModalViewControllerAnimated: (docs)
you can use another view with login screen and Save Bool value in nsuserdeafault then when app is start check for nsuserdefault and show view according to that.
then after you can call everywhere where you want in delegate.m or viewwillappear.
I have a Navigation Controller that is presented modally with 4 views in the stack. The final view has a done button that dismisses the modal view. When I then present the modal view again, it automatically goes to that last view instead of the first one. I added a line to pop to first view after dismissed but it adds a weird animation whether I set it to YES or NO. Maybe I'm doing it wrong?
- (void)dismissModalView
{
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] -4)] animated:YES];
}
Update:
This is the method used to present the modal view/navcontroller
- (void)showModalView
{
self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController presentModalViewController:self.optionsNavController animated:YES];
}
No, it looks right. If you want to retain the state of the Navigation controller then don't present it modally as it will get deallocated when you dismiss the view.
Modal views are usually used to present information that only needs to be shown briefly without maintaining the state of the view (i.e. about page, login page, settings page, etc).
Excuse me if I'm oversimplifying your issue, but if your need is to pop straight back to the first view controller, perhaps you could give the popToRootViewControllerAnimated: method a try instead of popToViewController:.
I'm not sure what the problem with the dismiss code you posted is, but the following should work:
- (void)showModalView
{
self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.optionsNavController popToRootViewControllerAnimated:NO];
[self.navigationController presentModalViewController:self.optionsNavController animated:YES];
}
Also, viewDidLoad is intended to only be called once every time the view is loaded, viewWillAppear a
First, I would like to warn that I am a complete newbie into iPhone coding...
I need to show up a viewcontroller from a library, I know that it is modal. I have a tab bar app (created with the default XCode template). I need to show that viewcontroller, there are no problem if it hides the tabbar itself... But I am quite clueless, I don't know even what to search, or what to read...
You can call presentModalViewController:animated: to display another UIViewController modally.
EDIT: If you want to display your modal view in response to a button touch (for example), you would display it like this:
- (IBAction)buttonTouched:(id)sender
{
ModalViewController* controller = [[ModalViewController alloc] init];
[self presentModalViewController:controller animated:YES];
[controller release];
}
Then when you want to dismiss the modal controller, call dismissModalViewControllerAnimated:. This can be called either on your main view controller, or the modal one.
I don't know even what to search, or
what to read...
View Controller Programming Guide is a good place to start to help you understand view controllers (including modal ones). If that's confusing, get a bigger picture with iOS Application Programming Guide or start at the very beginning.
You can call modal view as
YourViewController *yvc = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:YES]
[self presentModalViewController:yvc animated:YES];
You can call it in the IBAction method in case you want to call it on any control event like Button Click
-(IBAction)buttonClicked:(id)sender
{
YourViewController *yvc = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:YES]
[self presentModalViewController:yvc animated:YES];
}
You can call it using self.
Hope this helps you.
If you have more doubts on this then you can ask me.
I am using one navigation controller in my application. I am having one main view (with main view controller) and few options views. Options views are viewed by navigation controller when a button clicked on main view's toolbar.
Everything works as expected for first time. When I came back to main view from navigation controller and tries again to go to option view (i.e. navigation controller) my application crashes.
Following is my code,
//Jump to navigation controller from main view controller
optionsViewController *optionsView = [[optionsViewController alloc] initWithNibName:#"optionsView" bundle:nil];
navControllerSettings = [[UINavigationController alloc] initWithRootViewController:(UIViewController *) optionsView];
[self presentModalViewController:self.navControllerSettings animated:YES];
//Code to go back to main view from navigation controller
[self.navigationController dismissModalViewControllerAnimated:YES];
What is correct mechanism to handle navigation controller? Do I need to release/dealloc the navigation controller or options view?
Sample code will help better.
Your navigation controller only gets set up once, then you push and pop other views from its stack.
UINavigationController *navController = [[UINavigationController alloc] init];
UIViewController *yourMainViewController = [[yourMainViewControllerClass alloc] init];
// when you are ready to go to your options view
optionsViewController *optionsView = [[optionsViewController alloc] initWithNibName:#"optionsView" bundle:nil];
[navController pushViewController:optionsViewController animated:YES];
// the back button and the pop from the stack when it is hit is handled auto-magically for you
Thanks for the reply.
But my application architecture is, I am having one main view on which I display few things and having toolbar. Toolbar contains one button, after clicked on that this navigation controller gets created and displayed on the screen.
using back button I came on the main view. But then after I could not go on the navigation again as it is crashing while executing following line
[self presentModalViewController:self.navControllerSettings animated:YES];
What might be the problem here?
Vishal N
I had a similar problem to this with it crashing in presentModalViewController: on second attempt. The problem was caused by calling [self becomeFirstResponder] in viewDidAppear: inside the first UIViewController that I presented, but I failed to call [self resignFirstResponder] in viewWillDisappear:.