【发布时间】:2011-06-30 11:12:42
【问题描述】:
我决定开始学习一些 Obj-C。而且我认为Wikibooks wikidraw 应用程序将是一个很好的起点(在一些非常基本的“Hello World”程序之后)。我已经阅读了这些章节,现在我在“WikiDraws 视图类”的末尾。所以现在我应该能够编译和运行。当然是行不通的。一开始我遇到了很多错误,但我已经修复了大部分,只剩下 6 个。这是其中之一:
- (void) mouseDragged:(NSPoint) pt
{ NSPoint np; np.x = pt.x - _anchor.x; np.y = pt.y - _anchor.y; 如果(_dragState == 0){ // 拖动对象 [self offsetLocationByX:np.x byY:np.y]; } 否则如果(_dragState >= 1 && _dragState [自我设置边界:nb]; } }- (NSRect) newBoundsFromBounds:(NSRect) old forHandle:(int) whichOne withDelta:(NSPoint) p { // figure out the desired bounds from the old one, the handle being dragged and the new point. NSRect nb = old; switch( whichOne ) { ..........
所以在 NSRect nb = [self newBoundsFromBounds:... 我收到一条错误消息,“Invailid initializer”和“WKDShape 可能无法响应 '-newBoundsFromBounds:forHandle:withDelta:”- 。我该怎么办?我是编码新手,但渴望学习。
/卡尔-菲利普
【问题讨论】:
-
请复制并粘贴您收到的确切错误消息,并考虑发布整个源文件或项目。尤其是刚开始时,很难判断代码的哪一部分导致了错误,而且可能不是您想的那样。 (例如,您的问题已经模棱两可——您提到了
NSRect nb = ...,但该代码在您粘贴的 sn-p 中出现了两次。)
标签: objective-c cocoa macos