【问题标题】:Method definition not found in XcodeXcode 中找不到方法定义
【发布时间】:2014-07-20 12:46:05
【问题描述】:

使用 Xcode 5.1,Objective-C

刚开始尝试使用Objective-C,写了一个简单的程序,得到了一些警告:

未找到“某些方法”的方法定义...

我正在查看我的代码,并在实现文件 (.m) 中看到了方法 屏幕。

我知道 - 看到很多类似的问题:

  • Here - 字母大小写的差异 - 检查一切正常
  • Here - 调用 .m 文件中不存在的方法 - 检查 - 存在
  • Here - 与上一个相同的问题。问题
  • Here - 奇怪/非标准设置 Apple - 一切正常
  • Here - 不正确的实现
  • Here - 缺少参数,所以执行不正确
  • 以及其他相同的错误...

所以根据这篇文章,我认为问题在于缺少声明/实现或某些语法错误

检查我的代码是否一切正常。


声明 - 在 .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;

.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];
}

我才刚开始尝试使用 Xcode 的 Objective-C,也许我错过了什么

【问题讨论】:

  • 您是否尝试过清理和重建您的项目?
  • 多试几次——第一次我几乎没有错误和警告,现在只剩下一个

标签: ios objective-c xcode


【解决方案1】:

语法不正确。对于此方法,您的 .h 应如下所示(删除多余的冒号):

- (void)addAlbumWithTitle:(NSString *)title
               artist:(NSString *)artist
              summary:(NSString *)summary
                price:(float)price
      locationInStore:(NSString *)locationInStore;

苹果文档:

如果你需要提供多个参数,语法又是相当的 与 C 不同。指定了 C 函数的多个参数 括号内,以逗号分隔;在 Objective-C 中, 采用两个参数的方法的声明如下所示:

- (void)someMethodWithFirstValue:(SomeType)value1 secondValue:(AnotherType)value2;

在本例中,value1 和 value2 是实现中用于访问提供的值的名称 当方法被调用时,就好像它们是变量一样。

请参阅documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2011-08-06
    • 2014-08-11
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多