代码之家  ›  专栏  ›  技术社区  ›  Mausimo

iPhone Objective C-错误:在需要浮点值的地方使用指针值

  •  0
  • Mausimo  · 技术社区  · 14 年前

    照片h

    #import <CoreData/CoreData.h>
    
    @class Person;
    
    @interface Photo :  NSManagedObject  
    {
    }
    
    @property (nonatomic, retain) NSData * imageData;
    @property (nonatomic, retain) NSNumber * Latitude;
    @property (nonatomic, retain) NSString * ImageName;
    @property (nonatomic, retain) NSString * ImagePath;
    @property (nonatomic, retain) NSNumber * Longitude;
    @property (nonatomic, retain) Person * PhotoToPerson;
    
    @end
    

    照片.m

    #import "Photo.h"
    
    #import "Person.h"
    
    @implementation Photo 
    
    @dynamic imageData;
    @dynamic Latitude;
    @dynamic ImageName;
    @dynamic ImagePath;
    @dynamic Longitude;
    @dynamic PhotoToPerson;
    
    @end
    

    这是我创建的mapViewController.m类。如果我运行这个,CLLocationDegrees CLLat和CLLong行:

                    CLLocationDegrees CLLat = (CLLocationDegrees)photo.Latitude;    
                    CLLocationDegrees CLLong = (CLLocationDegrees)photo.Longitude;
    

    告诉我错误:在需要浮点值的地方使用了指针值。

    for(int i = 0; i < iPerson; i++)
            {
                //get the person that corresponds to the row indexPath that is currently being rendered and set the text
                Person * person = (Person *)[myArrayPerson objectAtIndex:i];
                //get the photos associated with the person
                NSArray * PhotoArray =  [person.PersonToPhoto allObjects];
                int iPhoto = [PhotoArray count];
    
            for(int j = 0; j < iPhoto; j++)
            {
                //get the first photo (all people will have atleast 1 photo, else they will not exist). Set the image
                Photo * photo = (Photo *)[PhotoArray objectAtIndex:j];
    
                if(photo.Latitude != nil && photo.Longitude != nil)
                {
                    MyAnnotation *ann = [[MyAnnotation alloc] init];
                    ann.title = photo.ImageName;
                    ann.subtitle = photo.ImageName;
    
                    CLLocationCoordinate2D cord;                    
                    CLLocationDegrees CLLat = (CLLocationDegrees)photo.Latitude;    
                    CLLocationDegrees CLLong = (CLLocationDegrees)photo.Longitude;
    
                    cord.latitude = CLLat;
                    cord.longitude = CLLong;
    
                    ann.coordinate = cord;
                    [mkMapView addAnnotation:ann];              
    
                }       
            }   
        }
    
    1 回复  |  直到 14 年前
        1
  •  5
  •   Michael Chinen    14 年前

    NSNumber不是浮点类型,而是指针,因此您需要执行以下操作来转换它:

    CLLocationDegrees CLLat = (CLLocationDegrees)[photo.Latitude doubleValue];    
    CLLocationDegrees CLLong = (CLLocationDegrees)[photo.Longitude doubleValue];