1

我遇到一个简单的问题,我试图从另一个类更改一个类的布尔值,但它没有发生,它返回NO

//在推送其他视图控制器之前

-(IBAction)editWOD
{
    self.editGirlController= [[AddGirlsView alloc] init];
    self.editGirlController.isEditModeON=YES;
    self.editGirlController.editgirls=girls;
    [self performSegueWithIdentifier:@"editModeGirls" sender:self];
}

添加女孩视图 .h

@interface AddGirlsView : UIViewController
{
    BOOL isEditModeON;

}
@property BOOL isEditModeON;

添加女孩视图 .m

@synthesize isEditModeON;
- (void)viewDidLoad
{
    [super viewDidLoad];
    if (isEditModeON==NO) {
        NSLog(@"Edit Mode is OFF");
    }
    else{
        [self populateViewOnEdit];
    }


}

代码有什么问题?

+++++++++添加答案+++++++++++++++++++

感谢乔尔,这是答案

-(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;
    }
}
4

2 回答 2

4

我认为问题在于您分配并初始化 AddGirlsView。当您执行 segue 时,它​​可能会重新实例化另一个 AddGirlsView。您应该在 prepareForSegue 中设置此变量。

if ([segue.identifier isEqualToString:@"editGirlsMode"]) {
    [segue.destinationViewController setIsEditModeOn:YES];
    [segue.destinationViewController setEditGirls:girls];
}
于 2013-01-28T18:24:18.420 回答
-4
@property (nonatomic) BOOL isEditModeON;
于 2013-01-28T18:23:54.080 回答