在 xCode 中找不到方法定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24850632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Method definition not found in xCode
提问by gbk
using xCode 5.1, Objective C
使用 xCode 5.1,目标 C
Just start to try use of Objective C, write a simple program, and got some Warning :
Method definition for "some method" not found...
刚开始尝试使用Objective C,编写一个简单的程序,并得到一些警告:
Method definition for "some method" not found...
I'm looking in to my code and i see method in implementation file (.m) Screen.
我正在查看我的代码,我在实现文件 (.m) 屏幕中看到了方法。
I know - see a lot of similar questions:
我知道 - 看到很多类似的问题:
- Here- differences in letter case - check all it's ok
- Here- calling to method that not exist in .m file - check - exist
- Here- same problem like in prev. question
- Here- weird/non-standard setup Apple - all OK
- Here- incorrect implementation
- Here- missed parameter, so incorrect implementation
- and other same errors...
- 在这里- 字母大小写的差异 - 检查一切正常
- 这里- 调用 .m 文件中不存在的方法 - 检查 - 存在
- 在这里- 与上一个相同的问题。题
- 在这里- 奇怪的/非标准设置 Apple - 一切正常
- 这里- 不正确的实现
- 这里- 缺少参数,所以不正确的实现
- 和其他相同的错误...
So according to this post, i think that the problem is or in missing declaration/implementation or some syntax's error
所以根据这篇文章,我认为问题在于缺少声明/实现或某些语法错误
Check my code looks like all is ok.
检查我的代码看起来一切正常。
Declaration - in .h file
声明 - 在 .h 文件中
//- mean non static method
//(return type) Method name : (type of var *) name of var
- (void)addAlbumWithTitle : (NSString *) title
//global name of var : (type of var *) local name of var
artist : (NSString *) artist :
summary : (NSString *) summary :
price : (float) price :
locationInStore : (NSString *) locationInStore;
Implementation in .m file
在 .m 文件中实现
- (void)addAlbumWithTitle:(NSString *)title
artist:(NSString *)artist
summary:(NSString *)summary
price:(float)price
locationInStore:(NSString *)locationInStore {
Album *newAlbum = [[Album alloc] initWithTitle:title
artist:artist
summary:summary
price:price
locationInStore:locationInStore];
[self.albumList addObject:newAlbum];
}
I'm just few a day like start to try Objective C with xCode, maybe I something missed
我只是一天开始尝试使用 xCode 尝试 Objective C,也许我错过了一些东西
回答by Salavat Khanov
The syntax is incorrect. Your .h should look like this for this method (remove extra colons):
语法不正确。对于此方法,您的 .h 应如下所示(删除多余的冒号):
- (void)addAlbumWithTitle:(NSString *)title
artist:(NSString *)artist
summary:(NSString *)summary
price:(float)price
locationInStore:(NSString *)locationInStore;
Apple Docs:
苹果文档:
If you need to supply multiple parameters, the syntax is again quite different from C. Multiple parameters to a C function are specified inside the parentheses, separated by commas; in Objective-C, the declaration for a method taking two parameters looks like this:
- (void)someMethodWithFirstValue:(SomeType)value1 secondValue:(AnotherType)value2;
In this example, value1 and value2 are the names used in the implementation to access the values supplied when the method is called, as if they were variables.
如果需要提供多个参数,语法又与 C 完全不同。C 函数的多个参数在括号内指定,用逗号分隔;在 Objective-C 中,带有两个参数的方法的声明如下所示:
- (void)someMethodWithFirstValue:(SomeType)value1 secondValue:(AnotherType)value2;
在此示例中,value1 和 value2 是实现中用于访问调用方法时提供的值的名称,就好像它们是变量一样。
Refer to the documentation.
请参阅文档。