0

我不能以任何方式引用它并让 void 运行。我可以在任何其他类中运行 void,只需创建一个函数并调用它,但在这个类中没有加载视图。所以问题是,我该如何运行它?

我试过从另一个类中引用变量,但它给出了编译器错误。

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];
     }
4

1 回答 1

0

在你打电话的另一个班级,写[sfAnnotation whateverMethodYouWantToCall];

例如,如果您想getCoords从其他类的 viewDidLoad 调用:

-(void)viewDidLoad{
    //Whatever code you have before.
    [sfAnnotation getCoords];
    //Whatever code you have after.
}
于 2013-01-10T00:18:27.857 回答