iPhone UITabBarController - iphone

I am using a UITabBarController with 3 items and am curious how to access a method from the first tab if I am on the second or third tab. The problem I am running into is I have a UIImageView on the first tab that is using core animation to loop continuously through 3 images. But when I switch to the second tab and try to switch back to the first tab the program hangs. I discovered if I stop the animation then it will let me switch back to the first tab fine. Any ideas?

You can access view controllers in UITabBarController using its viewControllers property (returns array of controllers) and get the one you need by its index.
The better way, however, is to try to stop animations in controller's -viewWillDisappear: method and resume animations in -viewWillAppear: .

Related

Can't use page based navigation after using presentController to change view?

When switching from a viewcontroller to another I face this problem were I can't navigate through the next page action from the vievcontroller that I land on.
Further explanation: I have 3 views and 3 different viewcontrollers. I do the first switch from the first to the second viewcontroller through code:
presentController(withName: "TimerController", context: s)
From the second viewcontroller I'm using the ctrl+drag method in the storyboard to do the next page action to the third controller. This worked fine before i implemented the pushController method. But doesn't seem to work now. The two little circles in the UI (indicating what view is showing) doesn't show up either.
Any thoughts on how to make this work again?
Found the answer to the problem. In order to do this I have to present all the controllers I want to be able to show in the next step.
presentControllerWithNames(["controllerOne", "controllerTwo"],
contexts: [contextObj1, contextObj2])
And now the next page segue is working again :)

Segues where a view replaces another

I'm planning a game app where a series of views are presented, one after the other, sequentially, in a loop.
I'm having a hard time figuring out the segue I should use for this (using the storyboard). It seems to me, that using the 'show' segue will result in a stack of views. In my app, you never go back from where you came, so does that mean that I could end up with dozens of views, one on top of each other?
Is there a way so that once you go into a segue, one view replaces the previous view?
Unfortunately you are not going to be able to do this with Storyboard segues as the "Replace" segue is only for SplitViewController (which sounds like wouldn't be right for what you are trying to do). Instead handle transitions through code. Have a base navigation controller and keep setting the new view controllers as the navigation controller's root view controller

view controllers using storyboard

i am trying to switch between two view controllers using storyboard. I create a modal seague by control-dragging (on buttons) from 1st view controller to 2nd, and then from the 2nd to the first.
So whenever I click on a button in 1st VC, it takes me to the 2nd VC. This time when i click the button on second VC, does it take me back to the original instance of the 1st VC or it creates a new instance?
If it takes me to the same instance, and user had written some data in some textfields, is there anyway to retain that on screen? (I might want to save them in some variables, and since the program will return back to the same instancem i'll be able to get the variables back)
If it doesn't take me to the same instance, is there any method to do so?
I tried making an instance of 2nd VC and using self.navigarionController push...(instance) but this doesn't swtich the controller.
If i do this pushing using the storyboard, and i do pop in my 2nd VC, it doesn't get popped either.
(and i would also couldn't understand the difference between push,modal and custom seagues)
Create the modal segue from VC1's button to VC2, but not the reverse one. When the VC2's button is tapped, call dismissViewControllerAnimated:completion: to return to where you were.
If you used a push segue instead, you would call popViewControllerAnimated: to go back but that only works if you have your view controllers managed by a UINavigationController.
You can think of push as a way of stepping through a sequence of related scenes while modal is something that's a bit out of the normal flow of the application. (That's not a firm rule but it's a starting point for deciding which way to go.) For 'custom', you write the segue code, so you decide what happens.

IOS 5 SDK and Segues

I am creating a project with Xcode 4.2 and using it's storyboard. In one of the views I have a button that a user will tap and it will perform some calculations. If the calculations are correct I need to display the view that they just came from. I am currently using a Navigation Controller. When the app starts it loads View 1. When I choose an option it loads View 2. If I click the 'back' button in the toolbar it loads View 1 with left animation.
In my IBAction method for the View 2 calculation I have the following snippet.
[self performSegueWithIdentifier:#"BackToView1" sender:sender];
But the problem is it loads View 1 using the left animation when I need it to load the right.
Would that be a custom segue? Am I missing something?
[Edit]
I just noticed something as well. When View 1 loads from my IBAction it appears it is initializing the AppDelegate again, whereas the 'back' button does not. I need to not initialize the AppDelegate since I am loading a data object at the start of the app. Calling init again kills my object.
You could try using the navigation controller to pop back. This will probably produce the effect you are after.
[self.navigationController popViewControllerAnimated:YES];

RetainCount for View Controllers in TabBarController -(aka releasing a tabBarController)

I have created an iPhone app where you start in a NavController and after a couple of levels you select an option from the table and an animated view pops in that has a tabbarcontroller at its root.
This is a completely seperate view that replaces the navcontroller. You tab around and when you want to go back to the options screen you press back and another animated transition plays swapping back the navigation controller removing the tab bar controller and releasing it.
The problem comes with releasing the UITabBarController. If you press the tab buttons to switch between tabs it seems you continually increase the reference count for the view controllers. Then when you call release on the tabBarController reference it will only release the view controller of the selected tab or any tabs you haven't viewed yet, and it takes one of the retain count on the others tabs viewcontrollers. This means you leak all your Model objects, custom cell objects etc from each of the other tabs that were not selected.
As an example of what I am seeing, if you create a new template TabBarController project in xcode and add a viewWillAppear method to the first view controller that prints out the retain count for itself. Start the app and press back and forth on the First and Second tab buttons and watch the log the retain count just keeps increasing.
So I am wondering if there is a way to release a tab bar controller and have it release all of its view controllers at the same time?
If this is true, it's a bug, and you should file a report on Apple Radar.
Just for completeness, I did post this problem in the apple dev forums looking for some confirmation but never heard anything back.
Checking out my app on OS3.0 shows that this behaviour is now fixed. Reference counts never go increase and releasing the UITabBarController appears to work.
Sadly I put a nasty hack in to fix this which doesn't play well with OS 3.0 so it's now conditional compilation time.