iphone - 初始化时类型不兼容?

标签 iphone objective-c ios double

为什么我在以下代码中收到“初始化中的不兼容类型”?

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/

相关文章:

ios - 我可以为 Twitter 和 Facebook 以外的社交网络创建或使用像 SLComposeViewController 这样的 View Controller 吗

ios - 以中间没有中间间距的方式设置 UICollectionViewCell 的大小

ios - canOpenURL : failed for URL: "instagram://app" - error: "This app is not allowed to query for scheme instagram"

iphone - 如何使部分的 UITableView 页脚不粘

ios - Xcode 调试 View 层次结构显示空白屏幕

objective-c - 如何使用 ZBar 阅读器的 scanCrop 属性?

ios - 很困惑使用我的类(class)是否正确

ios - Places API 未为 iOS 启用,即使它已经启用

ios - 设置 map 中心和缩放以适合所有坐标

iphone - Reverse facetime 摄像头是倒置的