- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Here I present swift vIEw controller CollectionVIEwController *cvc = [[CollectionVIEwController alloc] initWithNibname:@"CollectionVIEwController" bundle:nil]; UINavigationController *controller = [[UINavigationController alloc] initWithRootVIEwController:cvc]; [self.navigationController presentVIEwController:controller animated:YES completion:nil]; [[NSNotificationCenter defaultCenter] postNotificationname:@"BuildingReady" object:self userInfo:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:chosenBuilding,nil] forKeys:[NSArray arrayWithObjects:@"chosenBuilding",nil]]];}
我正在快速的课堂上听这个通知:
import UIKit@objc class CollectionVIEwController : UIVIEwController,UICollectionVIEwDataSource,UICollectionVIEwDelegate,UICollectionVIEwDelegateFlowLayout { overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() NSNotificationCenter.defaultCenter().addobserver(self,selector: "getBuilding:",name: "BuildingReady",object: nil) } func getBuilding(notification: NSNotification) { let userInfo: Dictionary<String,Building!> = notification.userInfo as! Dictionary<String,Building!> self.chosenBuilding = userInfo["chosenBuilding"] }
问题是,在swift类中,我从不捕获我的通知(func getBuilding从未被调用).
可能有一个对象是客观c类而第二个是快速类的问题吗?
dispatch_async(dispatch_get_main_queue(),^{ [[NSNotificationCenter defaultCenter] postNotificationname:@"BuildingReady" object:self userInfo:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:choosedBuilding,nil] forKeys:[NSArray arrayWithObjects:@"choosedBuilding",nil]]];});总结
以上是内存溢出为你收集整理的Objective-c类和swift类之间的NSNotificiation全部内容,希望文章能够帮你解决Objective-c类和swift类之间的NSNotificiation所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)