当我调用此函数时,它似乎返回一个指针而不是一个int。当我尝试NSLog返回值时,我收到一条警告“从不兼容的指针类型传递NSLog的参数1”。如果NSLog运行,它会崩溃。
这是否与静态方法有关?我怎样才能找回真正的int?
我正在使用SDK 3.0
这是有问题的功能:
+(int) getZoomFromExtent: (CLLocationCoordinate2D)bottomLeft
withTopRight:(CLLocationCoordinate2D)topRight
withPixelsX:(int)pixelsX
withPixelsY:(int)pixelsY
withMapContents: (RMMapContents*) contents;
这是.h代码:
#import <Foundation/Foundation.h>
#import <math.h>
#import <CoreLocation/CLLocation.h>
#import "RMTile.h"
#import "RMMapContents.h"
@interface AnnasMath : NSObject {}
+(CLLocationCoordinate2D) normalizePixelCoords:(CLLocationCoordinate2D) point;
+(RMTile)tileWithCoordinate:(CLLocationCoordinate2D)point andZoom:(int)zoom;
+(NSArray *)getTileArrayWithUpperLeft:(CLLocationCoordinate2D)upperLeft andLowerRight: (CLLocationCoordinate2D)lowerRight fromZoom:(int)bottomZoom toZoom:(int)topZoom;
+(int)getTileCountWithUpperLeft:(CLLocationCoordinate2D)upperLeft andLowerRight:(CLLocationCoordinate2D)lowerRight fromZoom:(int)bottomZoom toZoom:(int)topZoom;
+(int) getZoomFromExtent: (CLLocationCoordinate2D)bottomLeft
withTopRight: (CLLocationCoordinate2D)topRight
withPixelsX:(int)pixelsX
withPixelsY:(int)pixelsY
withMapContents: (RMMapContents*) contents;
@end
这是.m代码的开头:
#import "AnnasMath.h"
#import <Foundation/Foundation.h>
#import <math.h>
#import "TileWrapper.h"
@implementation AnnasMath
...
我使用它如下:
int zoom = [AnnasMath getZoomFromExtent:[[extent objectForKey:@"bottomLeft"]coordinate]
withTopRight:[[extent objectForKey:@"topRight"]coordinate]
withPixelsX:300
withPixelsY:300
withMapContents:t.mapVC.mapView.contents];
NSLog("About to set the zoom to %i", zoom);
答案 0 :(得分:10)
请注意,它表示“参数1” - 而您正在查看的变量是参数2.您将传递一个C字符串作为NSLog的第一个参数而不是NSString(编写为{{1}而不仅仅是@"something"
)。
答案 1 :(得分:1)
正确的字符串是:
NSLog(@"About to set the zoom to %i", zoom);
答案 2 :(得分:1)
我觉得你的功能是按你的意愿返回一个int。
您收到的编译警告实际上是NSLog的字符串参数...它需要一个Objective-C字符串,并且您将它传递给Cstring。
在字符串前加一个@,一切都应该好。