【问题标题】:linking a static library in ios在 ios 中链接静态库
【发布时间】:2012-07-30 01:27:39
【问题描述】:

我在 Xcode 4.4 中创建了一个基于数学的应用程序。我在故事板的帮助下使用基于标签栏的应用程序。

我已经在一个名为CalculationMethods 的单独类中编写了我所有的数学函数,它是NSObject 的子类。

我的视图控制器:

//  FirstViewController.h

#import <UIKit/UIKit.h>
#import "CalculationMethods.h"

@interface FirstViewController : UIViewController

@end

//  FirstViewController.m

#import "FirstViewController.h"
#import "CalculationMethods.h"

@interface FirstViewController ()

@end

@implementation FirstViewController



- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"%f",[self julianDateFinder: [self currentDayMonthAndYearFinder]]);
}

@end

如您所见,我在 FirstViewController.h 和 FirstViewController.m 文件中都包含了我的 CalculationMethod.h 文件,但是当我使用该类的方法时,例如 julianDateFindercurrentDayMonthAndYearFinder,Xcode 错误,说:

“'FirstViewController' 的无可见 @interface 声明选择器'CurrentDayMonthAndYearFinder'”

我是 iOS 和 XCode 的新手。谁能帮我解决错误?

【问题讨论】:

  • 您的 CalculationMethods.h 文件是什么样的?
  • 我也不认为您指的是客观 C 意义上的静态库。

标签: ios xcode4 static-linking


【解决方案1】:

在 FirstViewController 中,要使用 CalculationMethods 类中的任何方法,您需要创建一个 CalculationMethods 实例。然后使用以下语法访问方法:[instanceOfCalculationMethods aMethodInCalculationMethods];

例如你的情况,试试这个:

在 FirstViewController.h 文件中,@end 之前:

CalculationMethods *_calculationMethods;

并且在 viewDidLoad 方法中:

_calculationMethods = [CalculationMethods alloc] init];
NSLog(@"%f",[_calculationMethods julianDateFinder: [_calculationMethods currentDayMonthAndYearFinder]]);

【讨论】:

  • 谢谢!!!为了您的帮助,我实际上是 C 开发人员,并且对 iOS 开发完全陌生,感染这是我正在开发的第一个应用程序,所以我忘记了我创建了一个新类并且要首先使用一个类,我必须创建它的实例
  • 您也可以编写纯 C 风格的函数,并在 .h 文件中声明它们并在 .m 文件中实现它们。因此,您可以在没有指向 Obj-C 类实例的指针的情况下使用这些函数。但这将是另一个问题......:)
【解决方案2】:

我认为你误解了 Objective C 的工作原理。

如果不添加 CalculationMethods.h 头文件的详细信息,我帮不了你太多,但编译器警告告诉你 FirstViewController 没有方法 currentDayMonthAndYearFinder

出现这种情况的原因是因为您调用的是在 self 上执行选择器 CurrentDayMonthAndYearFinder,在您的 FirstViewController 实例的上下文中实际上是 FirstViewController 的实例

您自己说过您的方法 CurrentDayMonthAndYearFinder 在您的 CalculatorMethods 类上,因此我建议您创建 CalculatorMethods 类的实例或在 CalculatorMethods 类上调用名为 CurrentDayMonthAndYearFinder 的类方法。

这里的问题是你是否定义了实例方法或类方法。

你自己帮个忙,用CalculationMethods.h的内容更新你的问题

【讨论】:

  • 我已经实现了它
猜你喜欢
  • 2018-12-06
  • 1970-01-01
  • 2013-01-20
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多