ios - 如何在 block 中使用 NSTextView?

标签 ios objective-c block nstextview

我们知道Apple Transitioning to ARC Release Notes

Which classes don’t support weak references?

You cannot currently create weak references to instances of the following classes:

NSATSTypesetter, NSColorSpace, NSFont, NSMenuView, NSParagraphStyle, NSSimpleHorizontalTypesetter, and NSTextView.

Note: In addition, in OS X v10.7, you cannot create weak references to instances of NSFontManager, NSFontPanel, NSImage, NSTableCellView, NSViewController, NSWindow, and NSWindowController. In addition, in OS X v10.7 no classes in the AV Foundation framework support weak references.

所以问题是如何在 block 中使用 NSTextView?,如果不使用 weak, block 将持有 strong NSTextView 引用。

我担心应用无法释放 NSTextView。

我该怎么办?

最佳答案

试试下面:

NSTextView * __block textView = [[NSTextView alloc] init…];

为此添加 __block 以在 block 中解决问题,为了发布目的,您需要在完成 block 中或根据您的使用情况明确发布它。

关于ios - 如何在 block 中使用 NSTextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34508035/

相关文章:

ios - 循环不工作

ios - VR 中的 SceneKit 相机运动

iphone - 通过 itune 将文件集成到 iphone 后,文件位于 iphone 中的哪里

objective-c - 使用 UIImagePNGRepresentation 保存 UIImage 不保留我的图层修改

ios - UIScrollView动画问题

ios - OneSignal (iOS) - 未调用 didReceiveNotificationRequest

ios - iOS8 中的多行/动态 UILabel 截断

ios - 选择器没有已知的实例方法 'receivedItemsJSON'

java - 如何接受数组的输入

ruby-on-rails - 没有给定 yield 的 block