链接ios中的静态库

时间:2012-07-30 01:27:40

标签: ios xcode4 static-linking

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

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

我的ViewController:

//  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

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

  

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

我是iOS和XCode的新手。任何人都可以帮我解决错误吗?

2 个答案:

答案 0 :(得分:0)

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

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

这种情况的原因是因为您正在调用CurrentDayMonthAndYearFinder上的self执行选择器FirstViewControllerFirstViewController实例的上下文实际上是{CurrentDayMonthAndYearFinder的实例1}}

你自己说你的方法CalculatorMethods在你的CurrentDayMonthAndYearFinder类上,所以我建议你创建一个CalculatorMethods类的实例,或者在CalculatorMethods上调用名为CalculationMethods.h的类方法类。

这里的问题是天气与否,你已经定义了实例方法或类方法。

自己帮忙并使用{{1}}

的内容更新您的问题

答案 1 :(得分:0)

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

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

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

CalculationMethods *_calculationMethods;

在viewDidLoad方法中:

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