gpt4 book ai didi

ios - 在 Xcode 中找不到方法定义

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:16 28 4
gpt4 key购买 nike

使用 Xcode 5.1、Objective-C

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

Method definition for "some method" not found...

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

image of warning

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

  • 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,也许我错过了什么

最佳答案

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

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

Apple 文档:

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.

引用documentation .

关于ios - 在 Xcode 中找不到方法定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24850632/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com