gpt4 book ai didi

ios - objective-c 变量赋值不起作用

转载 作者:行者123 更新时间:2023-11-28 18:22:26 24 4
gpt4 key购买 nike

我想将函数参数放入一个数组中,但我这辈子都想不通。 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 上的属性或向其发送消息什么都不做。

关于ios - objective-c 变量赋值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17732370/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com