公共IB出口
我想在 B 类上使用 A 类的 IBOutlet
为什么这不起作用?
ClassA.h
@interface ClassA : UIViewController {
@public IBOutlet UILabel* myLabel;
}
@property (nonatomic, retain) UILabel* myLabel;
@end
ClassB.m
#import "ClassA.h"
#import "ClassB.h"
@implementation ClassB
ClassA.myLabel.text = @"Any String";
Xcode 发送此错误:内部编译器错误:分段错误
或者,还有其他方法可以做到这一点吗?这个问题快要死我了!
提前致谢
I want to use an IBOutlet from classA on classB
Why is this not working?
ClassA.h
@interface ClassA : UIViewController {
@public IBOutlet UILabel* myLabel;
}
@property (nonatomic, retain) UILabel* myLabel;
@end
ClassB.m
#import "ClassA.h"
#import "ClassB.h"
@implementation ClassB
ClassA.myLabel.text = @"Any String";
Xcode sends this error: internal compiler error: Segmentation fault
Or, is there another way to do this? This problem is killing me!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是直接从 XCode 复制粘贴的吗?你的代码看起来很奇怪。
- ClassB.m 不应包含 ClassA 的实现(这应该转到 ClassA.m)
- 您可能不需要 ClassA.myLabel.text,但需要 instance_of_ClassA.myLabel.text
如果这没有帮助,您能否提供更多信息?
Did you copy&paste this directly from XCode? Your code looks strange.
- ClassB.m should not contain the implementation of ClassA (this should go to ClassA.m)
- You probably don't want ClassA.myLabel.text, but instance_of_ClassA.myLabel.text
If this doesn't help, could you please provide some more information?
嗯,该代码看起来像是由 C++ 编码员编写的。不要跨越溪流。这是一个古老的问题,但我无法抗拒修复这样一个基本的错误。
ClassA.h
ClassB.m
ObjectiveC != C++ 或反之亦然(当然总是有 Objective C++)
Hmmm, that code looks like it was written by a C++ coder. Don't cross the streams. This is an ancient questions but I couldnt resist fixing such a basic error.
ClassA.h
ClassB.m
ObjectiveC != C++ or vice versa (of course there is always Objective C++)