0

I'm just starting out in iOS app development,so if this question seems foolish please bear with me. I'm creating a sample app where I have 2 view controllers.The first one has a full screen image,with a navigation bar and a camera roll button, which I use to pick a image from the galley when the app starts.Then I swipe to the second view controller where I enter some data like who clicked it,what camera was used etc in a text box.The second view controller has a navigation bar and a button Item in the navigation bar which I named back to return to the 1st view controller with the image.I have linked this button via the segue to the 1st view controller.Now with this setup everything is functional,but the only problem is when I load a image from the gallery and swipe to the second view to write the data,and then hit the back button to return to the first view, the image that I loaded from the gallery is no longer there and I'm presented with a blank screen.

So how can I make sure that I don't loose the loaded image when I swipe back from the second view controller to the first one?

Thanks any help would be appreciated.

OccamsRazor
  • 79
  • 1
  • 1
  • 7
  • Which method contains the code that displays the image? For the first controller, what do `viewWillAppear:` and `viewDidAppear:` look like? – Phillip Mills Jun 04 '12 at 21:54
  • @Phillip Mills I used the UIImagePicker, there is nothing like viewWillAppear: and viewDidAppear,though there is viewDidUnload:which has [self setImageview:nill] [super viewDidUnload]; and viewDidload which has [super viewDidLoad];. Thanks for the reply though. – OccamsRazor Jun 05 '12 at 07:11

1 Answers1

0

The problem is that you probably control dragged the button of the second view to the first view right? This doesn't "move" to that viewcontroller, this "creates" a new viewcontroller of the first type, which is why its empty. If you want to return to the first view controller you have to add the action for the button. You can simply "dismissViewController" if the data in the second one dissapears. Or make a strong pointer from controller 1 to controller 2 so that you can dismiss but then present it again if you want the information to not dissapear. (without the strong pointer the VC is unloaded when you dismiss it)

Pochi
  • 13,391
  • 3
  • 64
  • 104
  • Luis Oscar:No, the first view controller itself is not empty, as I said the Image which I load from from the gallery is empty,rest of the viewController is the same as before with the navigation bar other buttons etc. – OccamsRazor Jun 05 '12 at 07:06
  • @user1436094 it's a new instance of the first view controller, it has the same "format" but not the same state. Try embedding your first view controller in a UINavigationController and let the back button do it's work. – Moxy Jun 05 '12 at 07:37
  • @user1436094 very simple, on the firstviewcontroller viewdidappear method type NSLog(@"%@",self); then compare the number of the first time you see it to when you come back to it, it should be different. – Pochi Jun 05 '12 at 07:51
  • @LuisOscar The way to add a action to my button worked like a charm.Though it took a bit of a time to figure it out since I'm new to all this.Thanks for your help though :) – OccamsRazor Jun 07 '12 at 23:11