-1

Here is my method that my ViewControllerA implements as part of a NSNotification system:

- (NSInteger)updateTortoiseLevel:(NSNotification*)notification {
    _updateValue = 0;
    if ([notification.name isEqualToString:@"gameToTortoise"]) {
        NSNumber* update = [notification.userInfo objectForKey:@"gameToTortoise"];
        updateValue = [update integerValue];
    } else {
        // do other things
    }
    return _updateValue;
}

First off, I don't even know if I can return anything from this type of method, so let me know if I can't.

Here's what I'm after:

- (void)viewWillAppear:(BOOL)animated {
    if (_update == 1) {
        [self runCellUpdates];
    }
}

I'm using the notification system when I pop ViewControllerB to A. What happens first?...Does notification get sent before viewWillAppear:? If it doesn't, how can I use updateTortoiseLevel: inside viewWillAppear: if at all?

Do not mention "use delegate design pattern instead" because I already considered it but it will not work for my current design (at least 95% sure on that). Cheers

1 Answers1

0

First off, I don't even know if I can return anything from this type of method, so let me know if I can't.

Okay: You can't. Think about it. Who is calling you here? It's the runtime, delivering a notification. So there is no one for you to return a value to. The runtime is not going to wait to hear if you have a value to hand back in response, and even if you did, what do you imagine the runtime would do with it? The notion of returning a value in this situation is meaningless.

how can I use updateTortoiseLevel: inside viewWillAppear: if at all?

The question seems meaningless, but in any case my response would be: why would you want to? You are presumably getting the updateTortoiseLevel message with the notification and the NSNumber packed inside it, so why don't you do whatever it is you want to do in response right then and there inside updateTortoiseLevel?

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Fair enough, that's what I figured. So would I be able to use the incoming `NSNumber` for the conditional check in `viewWillAppear:`? Or is that also a dead-end type of situation? – Anthony Shintoluggenprog Nov 21 '16 at 01:01
  • @AnthonyShintoluggenprog I don't understand the question. In `viewWillAppear:`, in what sense is there an "incoming NSNumber"? The number is incoming if and when the notification is posted (and you are registered to receive it, presumably in such a way that your `updateTortoiseLevel` is called). Again, `viewWillAppear:` is something called by the runtime at its own meaningful moment — in this case, because your view is appearing. – matt Nov 21 '16 at 01:21
  • See my modified answer, since I am starting to be able to guess, in a hazy way, where you might think you're going with this... – matt Nov 21 '16 at 01:25
  • Wow.....did not think of that at all, I've been trying to gear everything to work with `viewDidAppear:`. So, if I can understand a little more, if I decided to run the conditional after I capture the `NSNumber` in `updateTortoiseLevel:`, when will that job be completed? Will I see the results when I pop back to `ViewControllerA`? `[self runCellUpdates];` will update the individual cells that need updating. Would I even need to call `viewWillAppear:` at that point? – Anthony Shintoluggenprog Nov 21 '16 at 01:33
  • "when will that job be completed?" Immediately. "Will I see the results when I pop back" Why not? If the VC A interface was updated while VC B was showing, then when you pop back to reveal VC A, that updated interface is what you'll see (as long as you don't do anything to mess it up). Try it and see what happens; the universe won't explode, you know. :) The worst that can happen is that it doesn't work, and then you can think about why that is. – matt Nov 21 '16 at 01:39
  • Hah! The Eternal Weakness of the Spotted Mind...this is my first time with notifications so I was a bit hesitant to just start error-honing-in on a solution. Also it worked like a charm, and the reloading of cells doesn't slow anything down in my collection view anymore. Thank you kind sir – Anthony Shintoluggenprog Nov 21 '16 at 01:47