- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Core Data,并且想知道我的做法是否正确。我正在使用下面的完成处理程序和 block 从单例对象打开我的 UIManagedDocument
。
[[self managedDocument] openWithCompletionHandler:^(BOOL success) {
if(success) {
NSLog(@"DOCUMENT: Success, Opened ...");
// TODO: Things to do when open.
// ...
// ...
}
}];
在我的 UIViewController
上,我设置了一个观察者来监视 UIDocumentStateChangedNotification
以指示我可以开始使用文档。
- (void)awakeFromNib {
NSLog(@"%s", __PRETTY_FUNCTION__);
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(documentIsReady) name:UIDocumentStateChangedNotification object:nil];
}
这看起来工作得很好,但我意识到我没有使用回调 block 。一种解决方案可能是创建我自己的通知并从 block 中发布该通知,它本质上执行相同的操作,但只是使代码更易于阅读。如有任何意见,我们将不胜感激。
最佳答案
我想说,如果您只需要通知一个 Controller 一次,并且仅在打开文档时(您有一个应用程序使用在 Controller 之间传递的单个 UIManagedDocument,如 CS193P 演示),那么它会最好只保留完成 block 内的代码。
但是,如果您的应用要多次打开和关闭文档,并且多个 Controller 必须了解该更改,则您应该使用通知。
关于iphone - UIManagedDocument CompletionHandler 和 NSNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12588547/
当我在 Debug模式下在 iPhone 模拟器中进行身份验证时,将运行下面代码中的第一个 if 语句。但是,当我在安装了 Evernote 客户端的 iPhone 上进行调试时,if 语句未被评估。
在我使用 URLSession.dataTask(with:completionHandler:) 创建新的 session 数据任务之后并通过调用其 resume() 来启动任务方法,鉴于应用程序在
我是今天扩展的新手,我收到了这个警告,有人知道如何匹配可选要求吗? Instance method 'widgetPerformUpdate(completionHandler:)' nearly m
我想了解 NSObject 可能属于哪个类(除 NSAlert、NSOpenPanel 和 NSSavePanel 之外),以便响应上述调用(如问题标题中所示)。这是我需要做的场景。菜单选择的操作必须
我在互联网上到处搜索,但无法真正处理我找到的答案。因此,如果有人可以在这里帮助我,我将不胜感激。 我写了一个看起来像这样的函数: func setImage(imageName: String, co
为什么我的完成处理程序出现问题,我该如何解决? func loadImageusingCacheWithUrlString(urlString: String) { self.image =
我试图将 bool 值传递给我的完成处理程序。当应用程序运行时,将 bool 传递给我的完成处理程序的结果决定了我显示的警报。如果我在错误检查中调用它,应用程序会崩溃/锁定。如果我在其他任何地方调用它
所以我试图让它在完成处理程序之后做一些事情,但我一直收到错误: expected CLGeocodeCompletionHandler class func didCompleteGeocoding(
我想为我的 completionHandler 默认参数传递: func firstFunc(completionHandler: ((array:[String:AnyObject] = [:])
我最近加入了一个新项目并开始研究 iOS 应用程序代码库。但是,在最新的 Xcode 10 中,代码不再编译。 protocol NetworkClientType { associatedtyp
以下代码是线程安全的吗?如果是这样,如何保证ByteBuffer 的安全发布?执行 CompletionHandler 的线程的实例? AsynchronousSocketChannel channe
This question already has answers here: Swift 3 URLSession.shared() Ambiguous reference to member 'd
在 Xcode 5.0.2 中设置要显示为模式表的 NSAlert 对象时,我遇到了一个有趣的惊喜。 我计划使用 beginSheetModalForWindow:modalDelegate:didE
我已经执行了代码,但收到completionHandler 错误 如果没有更多上下文,表达类型不明确 据我了解,这是由于completionHandler 不匹配造成的。如何为completionHa
我正在使用 AVAssetImageGenerator 从影片剪辑中获取图像,而无需先播放它。现在我有一个问题如何在处理程序的循环中设置变量?是否可以?我收到此错误消息,但不知道这意味着什么。 (谷歌
我已经执行了代码,但收到completionHandler 错误 如果没有更多上下文,表达类型不明确 据我了解,这是由于completionHandler 不匹配造成的。如何为completionHa
我试图在加载数据后加载我的 CollectionView,但我不知道应该如何使用 CompletionHandler 来执行此操作。感谢帮助我的代码如下:用于获取数据: func GETData(){
我正在尝试使用 openActiveSessionWithPublishPermissions 在 Facebook 上发布消息,因此如果用户未登录,他需要先登录,然后使用 io6 Facebook
我有以下方法,如果 SessionStatus 完成,我想返回 movieDestinationUrl,但是我不断收到此错误 Unexpected non-void return value in v
我有一个 UITextField,它允许用户为 Facebook 照片输入自定义相册名称。 textFieldShouldReturn 后,我将 textField.text 发送到 Facebook
我是一名优秀的程序员,十分优秀!