从另一个类设置 BOOL 属性
我可以知道如何将 BOOL 变量从一个类共享到另一个类吗?
这就是我正在尝试做的事情。我正在 SecondVC 处设置 FirstVC 的 BOOL 变量。当我尝试更改 BOOL 值时应用程序崩溃时,我在这里做错了什么。没有错误日志。
FirstVC.h
@interface FirstVC : UIViewController <UITextFieldDelegate>{
BOOL pickUpAddressIsSet;
}
@property (nonatomic) BOOL pickUpAddressIsSet;
@end
FirstVC.m
@synthesize pickUpAddressIsSet;
secondaryVC.m
NSArray *viewControllers = [self.navigationController viewControllers];
FirstVC *firstVC = (FirstVC *)[viewControllers objectAtIndex:viewControllers.count - 2];
firstVC.pickUpAddressIsSet = YES; // tried TRUE & 1
May I know how do I share a BOOL variable from one class to another class?
Here's what I am trying to do. I am setting the BOOL variable of FirstVC at SecondVC. What am I doing wrong here as the app crashes when I tried to change the BOOL value. With no error log.
FirstVC.h
@interface FirstVC : UIViewController <UITextFieldDelegate>{
BOOL pickUpAddressIsSet;
}
@property (nonatomic) BOOL pickUpAddressIsSet;
@end
FirstVC.m
@synthesize pickUpAddressIsSet;
secondVC.m
NSArray *viewControllers = [self.navigationController viewControllers];
FirstVC *firstVC = (FirstVC *)[viewControllers objectAtIndex:viewControllers.count - 2];
firstVC.pickUpAddressIsSet = YES; // tried TRUE & 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
它对我有用
Try this:
It works for me
看起来
firstVC
实例实际上并不是FirstVC
类型(类),这可以解释该错误。尝试以下操作:
您在 NSLog 输出中看到什么类型的类?
It seems like the
firstVC
instance isn't actually of the type (class)FirstVC
, that would explain the error.Try the following:
What kind of class do you see in the NSLog output?
应该是
冒号不应该在那里。
Should be
The colon should not be there.
我发现这是因为我试图在代码的其他部分将 BOOL 变量记录为字符串。
I found out that it's because I am trying to NSlog the BOOL variable as a string at other parts of the code.