Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在segue中设置目标视图控制器的bool值时出错_Ios_Objective C - Fatal编程技术网

Ios 在segue中设置目标视图控制器的bool值时出错

Ios 在segue中设置目标视图控制器的bool值时出错,ios,objective-c,Ios,Objective C,当我从SearchViewController切换到MatchCenterViewController时,我想将MatchCenterViewController中\u didAddNewItem的布尔值设置为是。我正试图这样做: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"ShowMatchCenterSegu

当我从
SearchViewController
切换到
MatchCenterViewController
时,我想将
MatchCenterViewController
\u didAddNewItem
的布尔值设置为
。我正试图这样做:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"ShowMatchCenterSegue"]) {
        MatchCenterViewController *controller = (MatchCenterViewController *) segue.destinationViewController;
        _didAddNewItem = YES;

        NSLog(@"we're about to set controller values before segueing to MC");
        // Send over the matching item criteria
        controller.itemPriority = self.itemPriority;

        if (_didAddNewItem == YES) {
           NSLog(@"Did add new item is YES");
        }
        [self.tabBarController setSelectedIndex:1];
    }
}
目标视图控制器是选项卡1,因此我想在切换到该选项卡之前设置bool。它正在注销“Did add new item is YES”,这告诉我,就在segue之前,bool的值确实是
YES

但是,在切换到目标时,当目标控制器的
viewdide
运行时,它会注销“不刷新”

我在原始VC和目标VC的头中设置了bool属性,如下所示:

@property (assign) BOOL didAddNewItem;

我很困惑我到底错过了什么

您混淆了对属性的访问和对自动合成iVar的访问

当你说

@property BOOL something;
不要使用
@synthesis
语句编译器会自动创建一个iVar
BOOL\u something
来存储属性。然后,您可以使用
self.something
\u something
访问此属性。你应该养成习惯,总是使用
self.something
(或者在另一个对象引用的情况下使用
object.something
),初始化器方法除外

在您的代码中,当您想要在目标控制器上设置属性时,您正在设置本地iVar _didAddNewItem-

 controller.didAddNewItem = YES;
 controller.didAddNewItem = YES;