UIViewcontroller not visible in my application - iphone

In my application, I have two UIViewcontrollers , When I push from first page to the second page and vise versa its working fine for the fist time. When I push it for second time from first to the second page the methods in the second page get called but not navigate to the second page its still in first page.
Please correct me if I have made some mistake. Thanks in advance.
I have used the below code
MYviewcontroller* vc = [[MYviewcontroller alloc]init];
[self.navigationController pushViewController:vc animated:YES];

For UINavigationController to work properly you gotta push(to the next page) and pop (back to previous page) correctly.
I see your code are pushing the ViewController correctly.
You just gotta pop your second VC back to previous VC by calling
self.navigationController.popToViewController(vc,animated:true)

Related

Login Logout View Controllers

I have a Login View where user enters username and password which is working fine to call the next view. Now when the user clicks logout, I am calling the Login viewController using following:
loginViewController *login = [[loginViewController alloc] initWithNibName:#"loginViewController" bundle:nil];
[self presentModalViewController:login animated:YES];
I don't know whether allocation the view again again on logout button action is a good idea.
I am using ARC but I dont know calling the loginViewController will push all the allocated memory of previous viewControllers.
PS:
loginViewController is the root view controler -ie- it is called right after the appDelegate.
I have tried popViewController method of the navigationController but it is not working.
Any other suggestion would be really grateful
As you are using ARC, the objects are managed by the iOS, so once you dismiss the loginViewController it will no longer available in memory. So you for next time you need to allocate & present the loginView again, your code is fine, works good..
I have a sample app made using tabBar with login & logout transitions. Here you can change your rootViewController as per your requirement.

Storyboard transition without any touch(i.e IBOutlet)

I am using storyboard,in which i have three view controllers. I want to go to 2nd view controller from first without any touch(so i used timer .)
I added following code to timers method:
[self presentModalViewController:anyViewControllerRef animated:YES];
or
[[self navigationController] pushViewController:anyViewControllerRef animated:YES];
but both the times i got blank screen after timers interval (even i got the logs perfectly, means the logs which i added in 2nd ViewControllers class but no visuals correctly)
What should i add to timers method to perform scene transition?(so able to see whatever i have added on next ViewController)
Just for your own reference, the reason why this was not working for you was because you were "creating" a viewcontroller of whatever type you had and showing this "newly created" controller, of course this one doesnt have any visuals on it because the interfacebuilder controller is NOT linked to this one.
Your solution means that instead of creating an instance of the anyViewControllerRef you are asking the storyboard to give you the one it holds (the one with the visual elements you added).
By the way almost 90% of the time you want to present modally a view controller under ios for iphone, push is only used for ipad or for navigationviewcontroller if i remember correctly.
Need to add identifier to next view controller and following code in timers method :
anyViewControllerRef = [self.storyboard instantiateViewControllerWithIdentifier:#"identifierName"];
[[self navigationController ] pushViewController:anyViewControllerRef animated:YES]

When trying to view table view after viewing another, app crashes

i have a tough one for you today. I have two tableViews in my app the first is on the first page. There are two other pages the user drills down to get to the second table view. After i leave the first table view, i can press the back buttons to get back perfectly until i reach the second table view. As soon as i drill down to the second table view and then try to return to the first via pressing the back buttons. As soon as i get to the last back button to return to the first table view, the app crashes. The code for the back buttons is simply:
- (IBAction)goBack:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
Any Help Would be greatly appreciated!! Thanks everyone!! :D
Whenever I create a modal view controller from a XIB, the automatic #property generator duplicates things in the Dealloc method, thus throwing an EXC_BAD_ACCESS when the view is dismissed. Make sure you aren't releasing something twice.
Sounds like your are releasing something too early. Open you app in instruments (command + i) and run a zombie test.
As soon as you see zombie has been messaged expand the right panel and have a look at the user code (your code) blocks. Indicated by the back person icon.
Double click that and it will indicate what it was trying to access that had already been released.
Are your tableviews being displayed in a modal window? If not, why are you calling [self dismissModalViewControllerAnimated:YES]? Shouldn't you be calling [[self navigationController] popViewControllerAnimated:YES]?
If you're using a UINavigationController, the back button functionality should be provided automatically.
if you are using [[self navigationController] popViewControllerAnimated:YES] to
then for back you write as mentioned below:
(IBAction)goBack:(id)sender {
// Tell the controller to go back
[self.navigationController popViewControllerAnimated:YES];
}
if you are using [self presentmodalviewcontroller: animated:]
then only [self dismissModalViewControllerAnimated:YES] will work
you try this [[self navigationController] popViewControllerAnimated:YES]

not getting tab view when we press back

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

Only title gets loaded when pushing uiViewController onto NavigationController - iPhone

I have a strange issue going on which I can't fathom. I have a number of uiViewControllers which I'm pushing onto a NavigationController - all fairly regular stuff. It's a bit of a drill-down application so after you've moved through 3 screens, the next view to be pushed doesn't actually appear - only the title changes in the Nav Bar. I'm pushing it the same way as all the others:
DisplayViewController *tempDispController = [[DisplayViewController alloc] initWithNibName:#"DisplayVC" bundle:nil];
[self.navigationController pushViewController:tempDispController animated:YES];
[tempDispController release];
The new title is set in the ViewDidLoad of the new ViewController - and that does animate in, but the actual view is still the old one.
EDIT: Forgot to say that it does load fine occasionally. Usually the first time but then not the next few times. Sometimes not even the first time.
Any ideas?
Thanks..
It sounds like the view controller is being pushed onto the stack, but its view has no content.
Solved it.. the viewController calling it was running a synchronous network call which hadn't completed by the time I was calling the next viewcontroller..
So, just made it an asynchronous connection and waited for the response before moving on. Also makes it better for showing progress to the user - and error handling.
Thanks for the responses though!