好的,我对错误感到困惑:
error: incompatible type for argument 1 of 'initWithFrame:'
这是造成它的原因:
operationLabel = [[NSTextField alloc] initWithFrame:CGRectMake(0, self.frame.size.height / 2 - (40 * 3), self.frame.size.width, 100)];
定义是:
- (id)initWithFrame:(NSRect)frameRect;
所以第一个参数是 NSRect,让我们检查一下:
typedef CGRect NSRect;
它怎么会导致错误呢? 它们是相同的类型,但名称不同!
最佳答案
除了 zoul 的回答之外,我想我会提到 Apple(从 10.5 开始)的两个辅助函数(宏?):
NSRect NSRectFromCGRect(CGRect cgrect)
CGRect NSRectToCGRect(NSRect nsrect)
关于objective-c - 为什么 NSRect 和 CGRect 是不兼容的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3538347/