Ich versuche, Benachrichtigung von Swift-Datei an Ziel c zu senden. Mein Versuch so weit:senden Benachrichtigung von Swift-Datei und erhalten in Ziel c-Datei in ios
ClassA.swift
override func viewDidLoad() {
super.viewDidLoad()
let containerDict:[String:AnyObject] = ["vwConatinerFrameWidth": vwContainer.frame.size.width, "vwConatinerFrameHeight": vwContainer.frame.size.height]
NSNotificationCenter.defaultCenter().postNotificationName("ContainerFrame", object: self, userInfo: containerDict)
let classB = ClassB(nibName: "ClassB", bundle: nil)
classB.willMoveToParentViewController(self)
self.vwContainer.addSubview(classB.view)
self.addChildViewController(classB)
classB.didMoveToParentViewController(self)
}
ClassB.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(containeFrameRecieved:)
name:@"ContainerFrame"
object:nil];
}
- (void)containeFrameRecieved:(NSNotification *)note {
NSDictionary *theData = [note userInfo];
if (theData != nil) {
CGFloat containerFrameWidth = [[theData objectForKey:@"vwConatinerFrameWidth"] floatValue];
CGFloat containerFrameHeight = [[theData objectForKey:@"vwConatinerFrameHeight"] floatValue];
NSLog(@"Width:%f and Height: %f",containerFrameWidth,containerFrameHeight);
}
}
My-Bridging-header.h
#import "ClassB.h"
Aber das Problem ist, der Wert kommt nicht zu ClassB. Kann mir jemand sagen, was mit diesem Code nicht stimmt?
zu erhalten Stellen Sie sicher, dass ClassB sich selbst als Beobachter hinzufügt, bevor ClassA die Benachrichtigung sendet. – damirstuhec
@damirstuhec: Ich habe aber nichts geändert. – Poles
'ClassA',' ClassB' scheint ViewController zu sein. Sind sie wirklich "am Leben"? Was ist ihr Lebenszyklus? – Larme