uitableviewsubviewtabbed-view

iOS - Tabbed aplication with table view and subview


I have one problem. in my app (it is tabbed style), I have one viewcontroller with some text and second with table view (RSS reader). When I have just the RSS and it is set to single view app, subview form rss works, but when I set up the tabbed app and click to some post in table view, subview didnt show up... Can anybody help me please?

Here are my codes:

AppDelegate.h

         #import <UIKit/UIKit.h>

@interface MWFeedParserAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

AppDelegate.m

#import "MWFeedParserAppDelegate.h"
#import "ViewController1.h"
#import "RootViewController.h"

@implementation MWFeedParserAppDelegate

@synthesize window;
@synthesize navigationController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after app launch
    UITabBarController *tbc = [[UITabBarController alloc]init];

    ViewController1 *vc1 = [[ViewController1 alloc]init];
    RootViewController *vc2 = [[RootViewController alloc]init];

    [vc1.tabBarItem setTitle:@"Tab1"];
    [vc2.tabBarItem setTitle:@"Tab2"];

    [tbc setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
    [window setRootViewController:tbc];
    return YES;
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Save data if appropriate
}

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
    [navigationController release];
    [window release];
    [super dealloc];
}


@end

Solution

  • From the dealloc, I see you are not using arc. You have some memory leaks; be sure to release vc1 and vc2 in your didFinishLaunchingWithOptions, the tab bar controller will retain them.

    You probably don't need navigationController property, recommend you delete that until you know you'll need it.

    I think you'll want to add your RSS view (vc2?) to a nav controller before adding to the tab bar controller like this:

    [tbc setViewControllers:[NSArray arrayWithObjects:vc1, [[[UINavigationController alloc] initWithRootViewController:vc2] autorelease], nil]];
    

    And delete this line:

    [window addSubview:[navigationController view]];
    

    Best of luck!!

    edit Spelled out a tad more:

    ViewController1 *vc1 = [[[ViewController1 alloc] init] autorelease];
    RootViewController *vc2 = [[[RootViewController alloc] init] autorelease];
    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc2] autorelease];
    UITabBarController *tbc = [[[UITabBarController alloc] init] autorelease];
    [tbc setViewControllers:@[vc1, navController]];
    [window makeKeyAndVisible];
    [window setRootViewController:tbc];