我不能以任何方式引用它并获得运行的空白。 我可以在任何其他类中运行void只是创建一个函数并调用它但在这个类中没有视图加载。所以Q是,我该如何运行呢?
我尝试引用其他类中的变量,但它会给编译器错误。
getCoords的返回值必须是double类型,因为它是坐标。
#import "OmarAnnotation.h"
#import <CommonCrypto/CommonHMAC.h>
#import <netdb.h>
#import "AppDelegate.h"
#import "MapViewController.h"
@implementation SFAnnotation
@synthesize image;
@synthesize latitude;
@synthesize longitude;
@synthesize string;
+(void) getCoords {
NSString *string = @"http://jerwuqu.info/iambored/?GETPOS";
NSURL *url = [NSURL URLWithString:string];
NSString *otherURLContents = [NSString stringWithContentsOfURL:url];
NSLog(otherURLContents);
NSArray* foo = [otherURLContents componentsSeparatedByString: @","];
NSString *longi = [foo objectAtIndex: 0];
NSString *lati = [foo objectAtIndex: 1];
NSLog(longi);
NSLog(lati);
double latiDouble = [lati doubleValue];
double longiDouble = [longi doubleValue];
}
- (CLLocationCoordinate2D)coordinate;
{
double extern *latiDouble;
double extern *longiDouble;
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = latiDouble;
theCoordinate.longitude = longiDouble;
return theCoordinate;
}
- (void)dealloc
{
[image release];
[super dealloc];
}
- (NSString *)title
{
return @"Omar";
}
// optional
- (NSString *)subtitle
{
return @"Ortdenhegen";
}
@end
//这是我在其他类文件中的viewDidLoad
- (void)viewDidLoad
{
self.mapView.mapType = MKMapTypeStandard; //Satelite?
self.mapAnnotations = [[NSMutableArray alloc] initWithCapacity:2];
SFAnnotation *sfAnnotation = [[SFAnnotation alloc] init];
[self.mapAnnotations insertObject:sfAnnotation atIndex:0];
[SFAnnotation getCoords]; // <- The line with an error
[self cityAction:self];
[self gotoLocation];
}
答案 0 :(得分:0)
在你正在打电话的其他课堂上,写下[sfAnnotation whateverMethodYouWantToCall];
例如,如果你想从另一个类的viewDidLoad中调用getCoords
:
-(void)viewDidLoad{
//Whatever code you have before.
[sfAnnotation getCoords];
//Whatever code you have after.
}