Objective c 未在类中设置另一个类中对象的值
在类中,我需要从另一个视图为标签设置值 要赋值的第一个类:Objective c 未在类中设置另一个类中对象的值,objective-c,set,Objective C,Set,在类中,我需要从另一个视图为标签设置值 要赋值的第一个类: #import "ViewDetailPoinmap.h" ... NSLog(@"On a cliqué sur : %@",[NSNumber numberWithInt:sender.tag]); //On a cliqué sur : 2130 ViewDetailPoinmap *detailPoint = [[ViewDetailPoinmap alloc] init]; detailPoint.idPoint = [
#import "ViewDetailPoinmap.h"
...
NSLog(@"On a cliqué sur : %@",[NSNumber numberWithInt:sender.tag]);
//On a cliqué sur : 2130
ViewDetailPoinmap *detailPoint = [[ViewDetailPoinmap alloc] init];
detailPoint.idPoint = [NSNumber numberWithInt:sender.tag];
detailPoint.txtIDPoint.text = [NSString stringWithFormat:@"%@", [NSNumber numberWithInt:sender.tag]];
另一个类(ViewDetailPoinmap.h):
(ViewDetailPoinmap.m)
问题出在哪里?在哪里创建
txtIDPoint
实例?您已经显示了尝试设置其文本的位置,但除非您初始化了标签本身,否则标签本身将为nil
,这与您描述的症状一致。您将属性标记为assign
,并且它引用了第一类中的变量。可能该变量已经自动释放
detailPoint.idPoint = [NSNumber numberWithInt:sender.tag]; // here you assign
尝试在此处更改
@属性(非原子,赋值)NSNumber*idPoint代码>分配给保留文本没有问题。NSlog返回值(null)=>NSlog(@“在到达后的第二页尾点:%@”,idPoint);我不明白。您希望我在第一个类中创建一个实例吗?别忘了在dealloc中释放它(如果未启用ARC的话)!已经有[detailPoint发布];在分配值的方法中,我指的是保留值的释放property@AlexandreOuicher,您是否尝试在此处更改属性(非原子,赋值)NSNumber*idPoint代码>分配以保留?让我们
...
@synthesize txtIDPoint;
@synthesize idPoint;
...
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"ON arrive sur la page détail du point : %@",idPoint);
//ON arrive sur la page détail du point : (null)
}
detailPoint.idPoint = [NSNumber numberWithInt:sender.tag]; // here you assign