簡體   English   中英

目標C變量分配不起作用

[英]Objective c variable assignment not working

我想將函數參數放入數組中,我一生都無法解決。 labelPoi是一個對象類,其中包含imageLocationX,imageLocationY和名稱。 我試圖將一個ViewController中找到的值分配給另一個ViewController中的值,但它對我不起作用。

這是在我的第一個ViewController中

PointOfInterest.imageLocationX = (((([self getDegreesFromRadians:angle_horizontal] / [self getDegreesFromRadians:FOV_Horizontal]))) *1024);
        PointOfInterest.imageLocationY = ((1-(([self getDegreesFromRadians:angle_to_bottom_of_view] / [self getDegreesFromRadians:FOV_Vertical])))*576);

PictureViewController *newlabel = [[PictureViewController alloc] display:PointOfInterest.imageLocationX andY:PointOfInterest.imageLocationY withName:PointOfInterest.name];

這是我的第二個ViewController(PictureViewController)

- (id)display:(double)imageXX andY:(double)imageYY withName:(NSString *)namee{
NSLog(@"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
NSLog(@"imageX: %f",imageXX);
NSLog(@"imageY: %f", imageYY);
NSLog(@"name: %@", namee);

labelPoi.imageLocationX = imageXX;
labelPoi.imageLocationY = imageYY;
labelPoi.name = name;
[transfer addObject:labelPoi];
NSLog(@"label.x: %f should be: %f", labelPoi.imageLocationX, imageXX);
NSLog(@"label.y: %f should be: %f", labelPoi.imageLocationY, imageYY);
NSLog(@"label.name: %@ should be: %@",labelPoi.name,namee);

return self;

}

這是輸出:

2013-07-18 14:21:14.731 AR_UAV_App[10641:11303] %%%%%%%%%%%%%%%%%%%%%%%%
2013-07-18 14:21:14.731 AR_UAV_App[10641:11303] imageX: 224.485718
2013-07-18 14:21:14.731 AR_UAV_App[10641:11303] imageY: 116.353401
2013-07-18 14:21:14.731 AR_UAV_App[10641:11303] name: Beutel Student Health Center
2013-07-18 14:21:14.731 AR_UAV_App[10641:11303] label.x 0.000000
2013-07-18 14:21:14.731 AR_UAV_App[10641:11303] label.y 0.000000 should be 116.353401
2013-07-18 14:33:29.882 AR_UAV_App[10700:11303] label.name: (null) should be: Beutel Student Health Center#############################################################

為什么

NSLog(@"label.x: %f should be: %f", labelPoi.imageLocationX, imageXX);

輸出0.00000?

編輯:這是我的Poi課,它是labelPoi

#import "Poi.h"

@implementation Poi
@synthesize longitude;
@synthesize latitude;
@synthesize name;
@synthesize x;
@synthesize y;
@synthesize distance;
@synthesize isVisibleToCamera;

-(id)initWithLatitude:(double)lat AtLongitude:(double)lon withName:(NSString *)name{
    self = [super init];
    if(self){
        self.latitude = lat;
        self.longitude = lon;
        self.name = name;
    }
    return self;
}

您需要分配和初始化labelPOI 它是nil ,並試圖訪問一個屬性,或發送郵件至, nil什么都不做。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM