1

This is my second day of learning ios programming with xcode - so this should be an easy quwstion - just that I can't figure it out.

I am using StoryBoards and an UITabViewController with 3 tab items. On the second tab I would like to start the camera, whenever the user selects that tab.

How can I detect that the second view is activated? Is there an event triggered in such cases?

bandreas
  • 869
  • 1
  • 8
  • 25
  • 2
    Implement the view controller's `viewWillAppear:` or `viewDidAppear:` method. – rmaddy Mar 08 '13 at 17:39
  • Thanks, it works - but not exactly as I want it to.... The point is that on this event I am showing the camera, so that the user can take a picture and after the picture is taken, the image is shown inside an ImageView of the ViewController. The point is that this event is fired also after the imagepicker is presented... how can i accomplish to do something just when the view is activated from the tabcontroller, or how can i distinguish between the sources of activation? – bandreas Mar 08 '13 at 17:53
  • Then explain what you really want compared to what actually happens. – rmaddy Mar 08 '13 at 17:55
  • ViewWillAppear and ViewDidAppear have the potential to be called multiple times even though the View Controller is loaded just once. Try ViewDidLoad if that works. – AC1 Mar 08 '13 at 17:59

1 Answers1

0

You can also use your ViewController's viewDidLoad method. Do whatever you need to in this method:

- (void)viewDidLoad
{
}
AC1
  • 463
  • 3
  • 9
  • As I mentioned above, I would need to start the camera just when the view is activated from the tabcontroller. Unfortunately viewDidLoad is called just once per application life (so far as I experienced this) and viewdidAppear is called even after the picture is taken.... – bandreas Mar 08 '13 at 18:07
  • You mentioned you want to activate the camera whenever the second tab is selected. I believe whenever you select that tab, that tab's view controller's viewDidLoad should be called. That's not the case? It might be possible that its not getting called if the view controller is already loaded in memory. In that case, yes, viewWillAppear/viewDidAppear is your best bet. Have some flag that determines when to enable the camera and when not to. – AC1 Mar 08 '13 at 18:12
  • 1
    yes, using a flag in viewWillAppear: or viewDidAppear: is fine. – bandreas Mar 08 '13 at 18:48