为什么我在以下代码中收到“初始化中的不兼容类型”?
NSString *latString = [NSString stringWithFormat:@"%@", @"-44.4349773"];
NSString *lngString = [NSString stringWithFormat:@"%@", @"-33.2779787"];
double latDouble = [latString doubleValue];
double lngDouble = [lngString doubleValue];
double roundDouble = 0;
NSNumber *mylngDoubleNumber;
if(latDouble == 0 && lngDouble == 0) {
NSNumber *mylngDoubleNumber = 0;
}else{
double tempDble = [self calcDiffDistance:latDouble withPostLng:lngDouble ]; <-- incompatible types...
NSNumber *mylngDoubleNumber = [NSNumber numberWithDouble:tempDble];
-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1 {
NSLog(@"beginning CLLocationDegrees in calcDiff in UsersPosts");
CLLocationDegrees lat = self.lastKnownLocation.coordinate.latitude;
CLLocationDegrees lng = self.lastKnownLocation.coordinate.longitude;
NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");
NSLog(@"beginning location1 in calcDiff in UsersPosts");
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:postLat longitude:lon1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:-44.4343 longitude:-34.977];
NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");
NSLog(@"beginning location release in calcDiff in UsersPosts");
double target = [location1 distanceFromLocation:location2];
//int myInt = (int)ceil(target);
target = target/1609.334;
[location1 release];
[location2 release];
NSLog(@"finsished location release in calcDiff in UsersPosts");
return target;
}
.h代码/////////////////////////////////
#import <UIKit/UIKit.h>
#import "PostTableCustomCellController.h"
#import "LoadMoreResultsTableViewCell.h"
#include <stdlib.h>
#import "CLController.h"
#import <CoreLocation/CoreLocation.h>
@class PostDetailViewController;
@interface TransactionsTableViewController : UITableViewController <CLControllerDelegate, UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate> {
IBOutlet UITableView *transactionsTableView;
NSMutableArray *postsArray;
PostDetailViewController *postDetailViewController;
UITableView *transTableView;
Boolean *isFetchingData;
int *webServiceAllCount;
NSCalendar *calendar;
NSTimer *minuteTimer;
NSTimer *regionsTimer;
Boolean *blockRefresh;
CLLocation *lastKnownLocation;
}
@property (nonatomic, retain) CLLocation *lastKnownLocation;
@property Boolean *blockRefresh;
@property (nonatomic, assign) Boolean *isFetchingData;
@property (nonatomic, retain) LoadMoreResultsTableViewCell *loadMoreResultsCell;
@property (nonatomic, assign) NSTimer *minuteTimer;
@property (nonatomic, assign) NSTimer *regionsTimer;
-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1;
- (NSString *)dateDiff:(NSString *)origDate;
- (void)updateTime:(NSTimer *)timer;
- (void)updateRegions;
-(void)newLocationUpdate:(CLLocation *)location;
-(void)newError:(NSString *)text;
@property (nonatomic, retain) UITableView *transTableView;
@property (nonatomic, retain) NSMutableArray *postsArray;
@property (nonatomic, retain) PostDetailViewController *postDetailViewController;
@end
最佳答案
看不到编译该代码的上下文的最佳猜测是,您没有导入声明方法 calcDiffDistance:withPostLng:
的头文件。
此外,int*
类型的实例变量几乎肯定不是您的意思;你真的想要一个指向 int
的指针吗?!
这个方法名称也有点粗糙:
-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1 {
像这样怎么样:
-(double)calculateDistanceFromLatitude:(double)lat longitude:(double)long
?
关于iphone - 初始化时类型不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5228916/