- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 unsafe_unretained 和 weak 关键字有一些疑问:读起来它们是完全相同的,唯一的区别是 weak如果指向的对象被释放,则将其设置为 null。
现在我使用下面的代码,它在 [instanceOfTheView setDelegate:self]
期间在点 [#2] 崩溃但是如果在 I4vMainView 声明 [#1] 中我替换
@property (nonatomic, weak) id <I4vDraggingFileProt> delegate;
与
@property (nonatomic, unsafe_unretained) id <I4vDraggingFileProt> delegate;
它工作得很好。这种行为的原因是什么?谢谢
详细信息:使用 ARC 编译目标 10.7。 Xcode 4.5.2。苹果LLVM 4.1
在 I4vMainView 类中,我有:
//----------- I4vMainView.h --------
@protocol I4vDraggingFileProt <NSObject>
-(void) anURLWasDeopped: (NSURL *) droppedUrl;
@end
@interface I4vMainView : NSView <NSDraggingDestination>{
NSImageCell *imageCell;
NSImage * image;
}
@property (nonatomic, weak) id <I4vDraggingFileProt> delegate; // [#1]
在调用者中
//----------- I4vViewController.h --------
@class I4vMainView;
@protocol I4vDraggingFileProt <NSObject>
-(void) anURLWasDeopped: (NSURL *) droppedUrl;
@end
@interface I4vViewController : NSViewController <I4vDraggingFileProt>{
I4vMainView * mv;
}
-(void) anURLWasDeopped: (NSURL *) droppedUrl;
@end
//----------- I4vViewController.m --------
@implementation I4vViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
}
return self;
}
- (void)loadView{
mv = [[I4vMainView alloc] init];
[mv setDelegate:self]; // <-- [#2]
[self setView:mv];
}
-(void) anURLWasDeopped: (NSURL *) droppedUrl{
// ...
}
@end
添加:
委托(delegate)声明为
@property (nonatomic, weak) id <I4vDraggingFileProt> delegate;
我有这个错误
<I4vMainView: 0x10060bf40> objc[4773]: cannot form weak reference to instance (0x10061bf10) of class I4vViewController
并且回溯彻底进行 _objc_trap <- objc_stroreWeak <- -[I4vMainView setDelegate:] <- [I4vViewController view]
最佳答案
我找到了答案:如 weak property for delegate cannot be formed 中所述
You cannot currently create zeroing-weak references to instances of the following classes (emphasis mine):
NSATSTypesetter, NSColorSpace, NSFont, NSFontManager, NSFontPanel, NSImage, NSMenuView, NSParagraphStyle, NSSimpleHorizontalTypesetter, NSTableCellView, NSTextView, NSViewController, NSWindow, and NSWindowController. In addition, in OS X no classes in the AV Foundation framework support weak references.
For declared properties, you should use assign instead of weak; for variables you should use __unsafe_unretained instead of __weak.
In addition, you cannot create weak references from instances of NSHashTable, NSMapTable, or NSPointerArray under ARC.
关于objective-c - __unsafe_unretained 与弱 : crash during setDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13845234/
我是 Arduino 世界的新手。编写了以下代码 - 使用 DHT22 传感器。 12 小时后,当温度低于所需温度时,我的温室的加热器没有打开。 关闭电源并重新打开后,一切恢复正常。我知道这段代码很乱
我正在使用 CENTOS6 和 REDHAWK2.0 (RH2.0)。基于“VirtualBox 5.0.16 for Windows host”和“VirtualBox 5.0.17 r106140
在无渲染模式下使用 VMR-9 时如何解决 SelectAtPosition() 崩溃? 最佳答案 使用无渲染模式时的 SelectAtPosition() 崩溃问题可以通过在自定义分配器中实现 IV
这是我从 logcat 复制的错误。我不知道为什么在应用设置屏幕中清除数据后应用程序崩溃。 02-20 17:22:29.980 839-1094/? I/InputReader: Apps
我收到了来自 Apple 的应用提交反馈: Thank you for your resubmission. We were unable to review your app as it crash
我有一个 iPad 应用程序。使用 Fabric 收集崩溃信息。最近出现了一些像 webthread EXC_BREAKPOINT 这样的崩溃。跟踪堆栈上没有我的代码。所以我不知道为什么会发生崩溃。
我有一个在 ubuntu(EC2 实例,t2.small)上运行的简单 python web-scraper,到目前为止它只打印出一个 url 列表: from bs4 import Beautifu
注意:我的问题之前已关闭,我尝试了此处提到的解决方案 - unknown error: session deleted because of page crash from unknown error
我正在尝试从一个场景过渡到另一个场景,但是当我调用 presentScene 时发生崩溃!场景未存储在类中或被引用,它们直接加载到 presentScene 调用中。 Xcode 崩溃截图: 我的简单
我有点困惑,我的应用程序几乎没有崩溃,崩溃日志也有以下信息。 崩溃:com.twitter.crashlytics.ios.exception 这是否意味着它是 Fabric 库的崩溃还是有效的崩溃?
我尝试在我的 ubuntu 16.04 远程服务器上使用 selenium webdriver 和 python 3.5.2 连接到网页 from pyvirtualdisplay import Di
我正在使用使用 Python 和 Selenium 的 InstaPy。我按 Cron 启动脚本,有时它会崩溃。所以它真的很不规则,有时它会很好地贯穿始终。我也已经在 GitHub Repo 上发帖,
最近我换了电脑,从那以后我无法使用 selenium 启动 chrome。我也尝试过 Firefox,但浏览器实例无法启动。 from selenium import webdriver d = we
我正在使用 InstaPy,它使用 Python 和 Selenium。我按照 Cron 启动脚本,但有时它会崩溃。所以它确实不规则,有时它贯穿得很好。我已经在 GitHub Repo 上发布了,但没
我正在使用 InstaPy,它使用 Python 和 Selenium。我按照 Cron 启动脚本,但有时它会崩溃。所以它确实不规则,有时它贯穿得很好。我已经在 GitHub Repo 上发布了,但没
我正在使用使用 Python 和 Selenium 的 InstaPy。我按 Cron 启动脚本,有时它会崩溃。所以它真的很不规则,有时它会很好地贯穿始终。我也已经在 GitHub Repo 上发帖,
我正在尝试使用rook在kubernetes集群上配置ceph,我已经运行了以下命令: kubectl apply -f common.yaml kubectl apply -f operator.y
我有一个屏幕A,在执行了一些POST API任务后,我启用了一个按钮,然后单击按钮导航到屏幕B。当Reaction Native应用程序冻结并崩溃时,崩溃会随机发生。从其他屏幕导航到屏幕B也不是问题,
我想知道操作系统是否可能导致崩溃,例如我是否有代码,它是否有可能在Windows环境下崩溃而在Linux上却没有崩溃?还是这不可能? 最佳答案 最简单的示例是代码,您的意图是使其与平台兼容,但是您的代
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我是一名优秀的程序员,十分优秀!