正如問題所述,我正在向兒童TVC發送通知,並且該兒童TVC無法收到通知並執行選擇器handleNotification: (NSNotification *) paramNotif
。即我不要從該選擇器獲得NSLog output
。子UITableViewController無法從父UITableViewController接收通知?
我的代碼如下,非常自我解釋。
我應該補充一點,我的父母TVC也收到來自模式場景的通知,並從dealloc
中刪除自己的中心,但它仍然應該工作,因爲它的父母?
家長的UITableViewController
在viewDidAppear
[self postNotificationToD5TVC];
在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];
這窩KS細正如我NSLogged的method
和stringWithBool
前的值Segue
兒童的UITableViewController
我有一個可變BOOL workout
在viewDidLoad中
[self setUpSliders:[self isRoutine]];
在- (BOOL)isRoutine
NSString *kNotifName2 = @"workout";
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(handleNotification:)
name:kNotifName2
object:nil;
BOOL isCorrectWorkout = workout;
return isCorrectWorkout;
在的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);
你爲什麼試圖爲父 - 子視圖控制器使用通知?你的目的是什麼? – Vaisakh
@Vaisakh如果已經從另一個視圖控制器對父對象進行更改。但是這個代碼仍然可以工作?你知道它爲什麼不是嗎? – Cescy
我知道我只能傳遞信息,但我想使用通知 – Cescy