0

I have two classes named InterfaceController and LoadInterfaceController.

I'm calling InterfaceController's uiChange function from my LoadInterfaceController:

InterfaceController *interfaceController = [InterfaceController alloc];
//[interfaceController performSelectorOnMainThread:@selector(uiChange) withObject:nil waitUntilDone:true];
[interfaceController uiChange];

The function is called, but the UI in InterfaceController isn't modified.

- (void)uiChange {
    NSLog(@"uiChange was called");
    //... make changes to the UI ...
}

If the function is called from a function originating from InterfaceController class the UI is changed, respectively.

I have tried calling uiChange on the main thread (as explained here), but the UI isn't responding. How may I specify the thread used for InterfaceController's UI?

Community
  • 1
  • 1
Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87

1 Answers1

1

The same issue as here. Do not initialise controllers on your own, let Watch do it as a user flow happens.

I'd suggest adding into your architecture a Pub/Sub pattern. The NSNotificationCenter class is a good example that implements one. It allows parts of application to communicate between each other and it is used really often for controllers communication as well.

Here is a good example of communication between an AppDelegate and controller that I provided answering to another question recently. But if you really need I could adopt it for your example.

Community
  • 1
  • 1
Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37
  • The issue still persist even when using `NSNotificationCenter` to communicate between classes. – Aleksander Azizi Sep 18 '15 at 07:55
  • @Aleksander Azizi - You should detail your task more. Why are you trying to trigger UI changes of another controller which is not showing at the moment? Use `willActivate()` method of the `InterfaceController` class in conjunction with a singleton model from the previous question to initialise your UI before loading. – Dmytro Hutsuliak Sep 18 '15 at 08:08
  • I should admit that using of `NSNotificationCenter` is more acceptable on iOS when nested `UIViewControllers' are used in other words more than one controller is displayed at the same time like here: http://stackoverflow.com/a/17499426/3242031 Try to use the approach from the previous comment. – Dmytro Hutsuliak Sep 18 '15 at 08:14
  • After data is passed on from the `LoadInterfaceController`, the `InterfaceController`'s `WKInterfaceTable` needs to be updated. This is managed with the `uiChange` function previously mentioned. – Aleksander Azizi Sep 18 '15 at 08:45
  • 1
    Sorry but I got confused with your task. I feel you do something wrong but anyway I'm happy this something works for you. – Dmytro Hutsuliak Sep 18 '15 at 09:16
  • You were right all along. The UI cannot be updated when initializing in a new instance. – Aleksander Azizi Oct 02 '15 at 07:47