【发布时间】:2014-01-26 05:38:10
【问题描述】:
在我的项目中,我在我的 FirstViewController 中声明了一个 BOOL *isOn。在 FirstViewController 中,我有两个按钮,按下 buttonOne,将 isOn 设置为 YES,buttonTwo 将 isOn 设置为 NO。在我的 SecondViewController 中,我试图运行一个引用 isOn 状态的 if 语句。我收到错误“不允许分配给 Objective-C 的‘只读’返回结果”。我怎样才能得到我想要的意图?
//FirstViewController.h
@property (assign) BOOL isOn;
- (IBAction)buttonOne:(id)sender;
- (IBAction)buttonTwo:(id)sender;
//FirstViewController.m
- (IBAction)buttonOne:(id)sender {
[self setIsOn:YES];
}
- (IBAction)offSiteButton:(id)sender {
[self setIsOn:NO];
}
//SecondViewController.m
#import "FirstViewController.h"
#import "FirstViewController.m"
FirstViewController *FVC
- (void)viewDidLoad {
if ([FVC isOn] = YES) { <----Error
// Do this
} else {
// Do that
}
如果我只是用...运行它
if ([FVS isOn])
if 语句返回 else 函数并为两个按钮“执行此操作”。请帮忙。
【问题讨论】:
-
我认为这行不通。即使使用 '==' 运算符。只是 nslog vc.isOn,我认为它会显示 nil
-
你是对的,但你能提供任何想法让它按我的意图工作吗?
标签: ios objective-c if-statement boolean viewcontroller