0

I'm currently writing an RSS program in which my splitViewController's views have to talk to each other. Both of them currently hold a propertied instance of each other which is declared in the App Delegate as mentioned below. I want to know if this is bad programming practice and what should I do to avoid it if so?

- (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;
}
Andy Ibanez
  • 12,104
  • 9
  • 65
  • 100
TheCodingArt
  • 3,436
  • 4
  • 30
  • 53

1 Answers1

0

If I'm understanding your question right you can do this but if its a true circular reference and both properties are "strong" then you may have a situation where they will never be released. Because of that if you have a back reference to an object then you want to use "weak" so it won't increment the retain count and hold onto it when it should be destroyed.

rooster117
  • 5,502
  • 1
  • 21
  • 19
  • Well, that's actually what I thought I should do.... so I did declare one of them as weak. I wasn't sure if this may be a problem because they are 'main' views. I wouldn't want one of my main views accidentally released lol. My other thought process was that they are my 'main' views.... so is it really a problem to have a possible retain cycle? I just wanted to ensure that this was ok in the coder's ethics book. – TheCodingArt Nov 21 '12 at 19:29