0

I have two ViewControllers. Let's call them aVC and bVC.

In aVC, I show an alertView. If you press a Button on that alertView, a segue is performed to bVC.

In bVC, something should happen when the view appears but only when triggered from that button in aVC.

I tried notifications.

When pressed Button of alertView in aVC, notification is posted. In viewDidLoad of bVC, I did addObserver for that notification, but this does not work.

I guess because the observer is added after post of the notification? That's only my guess.

I tried for hours to get that to work, but notifications does not seems to do the job.

So how can I call a method in bVC that is executed when the view appears triggered by that button of the alertview in aVC?

irie
  • 189
  • 1
  • 9
  • Sorry everyone, i am new here. Maybe it is a stupid question but why does my posts get corrected (capitalization and so on)? I thought this is the internet and not school ;) Please enlighten me ! – irie Feb 15 '14 at 21:48

2 Answers2

0

You could have a boolean property in bVC that defines whether bVC was loaded from the button in aVC or not. In prepareForSegue:sender:, set that property to true before you perform the segue (you can use sender to determine if the call came from your button), and in bVC, on appearance, check for said property.

An example on how to set such a property is in https://stackoverflow.com/a/9176361/886407.

Community
  • 1
  • 1
JiaYow
  • 5,207
  • 3
  • 32
  • 36
0

you can just call your method in viewDidLoad of bVC.

“When pressed Button of alertView in aVC, notification is posted. In viewDidLoad of bVC, I did addObserver for that notification, but this does not work” just like you guess , the observer is added after post of the notification.

Lee xw
  • 133
  • 9
  • Thx, but the method in bVC should not been called everytime the bVC appears, so i can not just put it in viewDidLoad. it should be called only if invoked by that button in aVC. But thx anyways ;) – irie Feb 15 '14 at 21:44
  • the viewDidLoad will not called everytime the bVC appears. – Lee xw Feb 16 '14 at 04:12
  • the viewDidLoad will call when the bVC is first loaded. – Lee xw Feb 16 '14 at 04:13