gpt4 book ai didi

objective-c - 委托(delegate)的奇怪情况

转载 作者:行者123 更新时间:2023-11-29 04:46:46 26 4
gpt4 key购买 nike

这是我的AppDelegate.h(我已经在Appdelegate.m中综合了这个属性)

{
NSString *uName;
NSDictionary *messagesDict;
NSString *serve1r;
NSDictionary *firstGet;
}
@property (strong, nonatomic) UIWindow *window;
@property (copy, readwrite) NSString *uName;
@property (copy, readwrite) NSString *serve1r;
@property (retain, nonatomic) NSDictionary *firstGet;

我有 TreeView Controller ,通过文本字段我输入一些用户信息并希望在其他 View Controller 中共享这些对象(用户名、服务器IP..)。我在其他类(SecondVC 和 ThirdVC)中分配新变量,如下所示:

MyDelegate *sharedDa= (MyDelegate *)([[UIApplication sharedApplication]delegate]);

在此之后,我可以在第二类中看到 uName(将其记录或显示在文本字段上),但我在第三类中看不到任何内容。我的代码有什么问题有人可以帮忙吗?

最佳答案

这取决于您如何在 View Controller 中设置此属性,因为使用复制属性,您将使用特定类型的 setter/getter。 (参见此处:NSString property: copy or retain?)

我建议您使用(强,非原子),这样您将始终保留指向同一对象的指针。 (当然,如果 - 并且应该如此 - appDelegate 实例始终相同)

关于objective-c - 委托(delegate)的奇怪情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9516960/

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