Problem is I have not invoked the child TVC. So when the notification is being sent from the parent to the child, the child is not listening to the notification. So when the child TVC loads it cannot "go back" and listen to the previous notificiations.
Child UITableViewController can't receive notification from Parent UITableViewController?
-
13-10-2022 - |
Question
As the question states, I am sending a notification to a child TVC and that child TVC is unable to receive the notification and excute the selector handleNotification: (NSNotification *) paramNotif
. I.e. I do not get the NSLog output
from that selector.
My code is below and is very self explanatory.
I should add that my parent TVC is also receiving a notification from a modal scene and removing itself from the center in dealloc
, however it should still work because its the parent?
Parent UITableViewController
In viewDidAppear
[self postNotificationToD5TVC];
In postNotificationToD5TVC
NSString *stringWithBOOL = [NSString stringWithFormat:@"%i",[self.workoutRoutine boolValue]];
NSString *kNotifName2 = @"workout";
NSNotification *notification = [NSNotification notificationWithName:kNotifName2 object:self userInfo:@{@"kworkout": stringWithBOOL}];
[[NSNotificationCenter defaultCenter] postNotification:notification];
This works fine as I have NSLogged the method
and the value of stringWithBool
before Segue
Child UITableViewController
I have a variable BOOL workout
In viewDidLoad
[self setUpSliders:[self isRoutine]];
In - (BOOL) isRoutine
NSString *kNotifName2 = @"workout";
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(handleNotification:)
name:kNotifName2
object:nil;
BOOL isCorrectWorkout = workout;
return isCorrectWorkout;
In handleNotification:(NSNotification *) paramNotif
NSString *workoutString = paramNotif.userInfo[@"kworkout"];
NSInteger workoutInt = [workoutString integerValue];
workout = workoutInt;
NSLog(@"Received notification in D5TVC and value of bool is %i",workout);
No correct solution
OTHER TIPS