1

您好我正在尝试为嵌套在 NSMutableArray 内的视图控制器设置属性,例如我在这个数组中有 3 个视图控制器:

FirstViewController *firstViewController = [FirstViewController alloc];
SecondViewController *secondViewController = [SecondViewController alloc];
ThirdViewController *thirdViewController = [ThirdViewController alloc];


NSMutableArray *viewControllerClasses = [[NSMutableArray alloc] initWithObjects:
                                         firstViewController,
                                         secondViewController,
                                         thirdViewController,                                       
                                         nil];


for (int x=0; x<[viewControllerClasses count]; x++) {

    // as an example to set managedObjectContext I otherwise would set firstViewController.managedObjectContext = context;

    [viewControllerClasses objectAtIndex:x].managedObjectContext = context;
}

但这会导致错误:请求成员“managedObjectContext”不是结构或联合。“firstViewController”不应该与 [viewControllerClasses objectAtIndex:0] 相同吗?

4

2 回答 2

3
于 2010-05-08T18:37:07.587 回答
0

You may try casting [viewControllerClasses objectAtIndex:x] returns an arbitary NSObject that doesn't have managedObjectContext property, so try using ((FirstViewController *)[viewControllerClasses objectAtIndex:x]).managedObjectContext = context;

于 2010-05-08T18:37:40.567 回答