【发布时间】:2014-06-17 18:39:19
【问题描述】:
我无法从视图控制器调用类方法。类方法将 BOOL 作为输入。 Xcode 允许我在没有参数的情况下调用它(这显然会崩溃),但是当我传递参数时会报错。
以下是相关代码:
// RLI.h
@interface RLI : NSObject <CLLocationManagerDelegate>
...
+(BOOL)askForLocationAccess;
end
// RLI.m
@implementation RLI
...
+(BOOL)askForLocationAccess:(BOOL)ask {
...
return answer;
}
end
// CLOnboardingViewController.m
@implementation CLOnboardingViewController
...
-(IBAction)allowGPSAccess:(id)sender {
// NSLog(@"%@", [sender currentTitle]);
BOOL ask = [[sender currentTitle] isEqualToString:gpsLabel];
[RLI askForLocationAccess:YES]; // No known class method for selector 'askForLocationAccess:'
[RLI askForLocationAccess]; // no complaint but crashes with "unrecognized selector sent to a class"
[RLI askForLocationAccess:ask]; // what I intend to do
...
}
end
如果需要更多代码,请告诉我,但这似乎应该足够简单。我查看了一堆“没有已知的选择器类方法”问题,但其中大多数要么是拼写错误,要么是调用实例方法。
【问题讨论】:
标签: ios objective-c class-method