0

我目前正在编写一个 RSS 程序,其中我的 splitViewController 的视图必须相互通信。它们目前都持有彼此的属性实例,如下所述,在 App Delegate 中声明。我想知道这是否是不好的编程习惯,如果是,我应该怎么做才能避免它?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.
    FCListViewController *lvc = [[FCListViewController alloc]initWithStyle:UITableViewStylePlain];
    UINavigationController *masterNav = [[UINavigationController alloc] initWithRootViewController:lvc];



    FCContentViewController *cvc = [[FCContentViewController alloc] init];

/*----------------------------------------- */ //<---------My question lies here

    [lvc setContentViewController:cvc];
    [cvc setListViewController:lvc];

/ ----------------------------------------- /

    //[lvc setWebViewController:wvc];

    //[[lvc navigationItem]setTitle:@"Falcon RSS Feed"];

   // [[self window] setRootViewController:masterNav];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:cvc];
        NSArray *vcs = [NSArray arrayWithObjects:masterNav, detailNav, nil];
        UISplitViewController *svc = [[UISplitViewController alloc] init];


        [svc setDelegate:cvc];
        [svc setViewControllers:vcs];

        [[self window]setRootViewController:svc];
          [[svc view] setBackgroundColor:[UIColor clearColor]]; //eliminates annoying black background for the listViewController when rotated

    }
    else{
        [[self window] setRootViewController:masterNav];
    }

    UIColor *blueHue = [UIColor colorWithRed:.2 green:.3 blue:.5 alpha:.7];
    self.window.backgroundColor = blueHue; //Sets upper most background.. noticed when rotating
    [self.window makeKeyAndVisible];
    return YES;
}
4

1 回答 1

0

如果我正确理解您的问题,您可以这样做,但如果它是一个真正的循环引用并且两个属性都是“强”的,那么您可能会遇到永远不会释放它们的情况。因此,如果你有一个对象的反向引用,那么你想使用“弱”,这样它就不会增加保留计数并在它应该被销毁时保留它。

于 2012-11-20T23:58:28.637 回答