问题描述
我遇到一个简单的问题,我试图改变从另一个类的一类布尔值,但情况并非如此,它返回 NO
。
//推其他的ViewController之前
- (IBAction为)editWOD
{
self.editGirlController = [[AddGirlsView的alloc]初始化];
self.editGirlController.isEditModeON = YES;
self.editGirlController.editgirls =女孩;
[个体经营performSegueWithIdentifier:@editModeGirls发件人:个体经营];
}
AddGirlsView .H
@interface AddGirlsView:的UIViewController
{
BOOL isEditModeON;}
@property BOOL isEditModeON;
AddGirlsView .M
@synthesize isEditModeON;
- (无效)viewDidLoad中
{
[超级viewDidLoad中];
如果(isEditModeON == NO){
的NSLog(@编辑模式是OFF);
}
其他{
[个体经营populateViewOnEdit]
}
}
哪些错误与code?
+++++++++答案ADDED +++++++++++++++++
在这里感谢乔尔就是答案
- (IBAction为)editWOD
{
[个体经营performSegueWithIdentifier:@editModeGirls发件人:个体经营];
}
- (无效)prepareForSegue:(UIStoryboardSegue *)赛格瑞发件人:(ID)发送者
{
如果([SEGUE符] isEqualToString:@editModeGirls])
{
AddGirlsView * editGirlController = [赛格瑞destinationViewController]
editGirlController.isEditModeON = YES;
editGirlController.editgirls =女孩;
}
}
我认为这个问题是你的alloc和init AddGirlsView。当您执行SEGUE它可能重新实例化另一个AddGirlsView。您应该设置在prepareForSegue这个变量。
如果([segue.identifier isEqualToString:@editGirlsMode]){
[segue.destinationViewController setIsEditModeOn:YES];
[segue.destinationViewController setEditGirls:女生];
}
I encounter a simple problem , I am trying to change the bool value of a class from another class but it is not happening, it returns NO
.
//before pushing other viewcontroller
-(IBAction)editWOD
{
self.editGirlController= [[AddGirlsView alloc] init];
self.editGirlController.isEditModeON=YES;
self.editGirlController.editgirls=girls;
[self performSegueWithIdentifier:@"editModeGirls" sender:self];
}
AddGirlsView .h
@interface AddGirlsView : UIViewController
{
BOOL isEditModeON;
}
@property BOOL isEditModeON;
AddGirlsView .m
@synthesize isEditModeON;
- (void)viewDidLoad
{
[super viewDidLoad];
if (isEditModeON==NO) {
NSLog(@"Edit Mode is OFF");
}
else{
[self populateViewOnEdit];
}
}
Whats wrong with the code?
+++++++++ANSWER ADDED+++++++++++++++++
thanks to Joel here is the answer
-(IBAction)editWOD
{
[self performSegueWithIdentifier:@"editModeGirls" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"editModeGirls"])
{
AddGirlsView *editGirlController = [segue destinationViewController];
editGirlController.isEditModeON=YES;
editGirlController.editgirls=girls;
}
}
I think the issue is that you alloc and init AddGirlsView. When you perform a segue it is probably re-instantiating another AddGirlsView. You should be setting this variable in prepareForSegue.
if ([segue.identifier isEqualToString:@"editGirlsMode"]) {
[segue.destinationViewController setIsEditModeOn:YES];
[segue.destinationViewController setEditGirls:girls];
}
这篇关于无法从另一个类,IOS改变BOOL值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!