Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 我在addViewController中有NSString值,我想在DetailsViewController的UILabel中显示该值_Iphone_Nsstring_Uilabel - Fatal编程技术网

Iphone 我在addViewController中有NSString值,我想在DetailsViewController的UILabel中显示该值

Iphone 我在addViewController中有NSString值,我想在DetailsViewController的UILabel中显示该值,iphone,nsstring,uilabel,Iphone,Nsstring,Uilabel,我是编程新手。任何帮助都将不胜感激 它在AddViewController中 NSLog(@"Am Currently at %@",locatedAt); DetailsOfPeopleViewController *details=[DetailsOfPeopleViewController alloc]; details.testAddressStr=[NSString stringWithFormat:@"%@",locatedAt]; details.testAddressS

我是编程新手。任何帮助都将不胜感激

它在AddViewController中

NSLog(@"Am Currently at %@",locatedAt);

DetailsOfPeopleViewController *details=[DetailsOfPeopleViewController alloc];
   details.testAddressStr=[NSString stringWithFormat:@"%@",locatedAt];
details.testAddressStr
在此处显示该值,但它不会将该值传递给DetailsViewController

NSLog(@"Am Currently at %@",locatedAt);

DetailsOfPeopleViewController *details=[DetailsOfPeopleViewController alloc];
   details.testAddressStr=[NSString stringWithFormat:@"%@",locatedAt];
locatedAt
的值显示在AddViewController中。当我尝试在DetailsViewController类的UILabel中显示该值时,它不会在标签中显示该值

详细信息请参见iewcontroller.h:

NSString *testAddressStr;

@property(nonatomic,strong) NSString *testAddressStr;
@property(nonatomic,retain)IBOutlet UILabel *addressLabel;
详细信息请参见iewcontroller.m:

 [addressLabel setText:testAddressStr];
我也这样尝试:

addressLabel.text=[NSString stringWithFormat:@"%@",testAddressStr];

我没有真正理解我犯的错误…

问题是由于您正在分配一个自动释放的变量。在您将其显示在detailView上之前,它将被释放。所以你需要保留它。或者您需要分配
测试地址str

只需替换这一行:

details.testAddressStr=[NSString stringWithFormat:@"%@",locatedAt];
details.testAddressStr = [[NSString stringWithFormat:@"%@",locatedAt] retain];
与:

details.testAddressStr=[NSString stringWithFormat:@"%@",locatedAt];
details.testAddressStr = [[NSString stringWithFormat:@"%@",locatedAt] retain];

details.testAddressStr = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@",locatedAt]];

将字符串
保留在初始化它的位置。
像这样

[locatedAt retain];

享受编程的乐趣

在Objective-C中没有“对象的范围”这样的东西。范围规则与对象的生命周期无关-保留计数就是一切

您通常需要声明实例变量的所有权。请参阅Objective-C内存管理规则。对于保留属性,您的属性设定者将声明新值的所有权,并放弃旧值的所有权。对于assign属性,周围的代码必须这样做,这在责任和关注点分离方面同样混乱。使用assign属性的原因是无法保留该值(如BOOL或NSRect等非对象类型)或保留该值会导致不必要的副作用

顺便说一句,对于NSString,正确的属性类型通常是copy。这样,如果有人传入一个NSMutableString(这是有效的,它是一种NSString),它就不能从您的下方变出来。

尝试替换

 [addressLabel setText:testAddressStr];
有以下几点

 [addressLabel setText:self.testAddressStr];
您可以使用

设置值

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSString stringWithFormat:@"%@",txtView.text]; forKey:@"testPersonNotesStr"];
[defaults synchronize];
testPersonNotesStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"testPersonNotesStr"];
NSLog(@"PERSON NOTE is........ %@",testPersonNotesStr);  
GetValue

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSString stringWithFormat:@"%@",txtView.text]; forKey:@"testPersonNotesStr"];
[defaults synchronize];
testPersonNotesStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"testPersonNotesStr"];
NSLog(@"PERSON NOTE is........ %@",testPersonNotesStr);  

:)

您在哪里调用[addressLabel setText:testAddressStr];正在调用[addressLabel setText:testAddressStr];这将在DeatilViewController的viewDidLoad中执行。谢谢你的快速回复。嘿,苏瓦纳+1 bhi karo na yaar…)嘿,实际上我不知道如何+1。我通过点击空的标志符号接受了答案,然后它变成了绿色标志符号…这是制作+1 r8的方法??只需点击我答案附近的上箭头。。。比如:-^这是upvo的符号实际上我想要的是,我需要在UILabel…NSLog(@“addressLabel.text ISSS…%@”,addressLabel.text)的其他视图中显示NSString的值(它在自己的视图中显示);NSLog(@“testAddressStr iss%@”,testAddressStr);如果我这样打印,它会显示为(null).@suvarna:你在其他地方分配testAddressStr吗?嘿!!!我解决了这个问题…对我的应用程序进行了一些其他定制…感谢所有的线索。。。