2013-02-16 59 views
0

我有一個問題。在我的應用程序中(它是選項卡樣式),我有一個viewcontroller與一些文本和第二個與表視圖(RSS閱讀器)。當我只有RSS和它被設置爲單視圖應用程序,子視圖形式rss的作品,但是當我設置選項卡式的應用程序,並在表視圖中點擊一些職位,子視圖沒有顯示...任何人都可以幫助我嗎?iOS - 帶表格視圖和子視圖的選項卡式應用程序

這裏是我的代碼:

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 

回答

1

從dealloc的,我看你是不是使用弧。 你有一些內存泄漏;一定要在您的didFinishLaunchingWithOptions中發佈vc1vc2,標籤欄控制器將保留它們。

你可能不需要navigationController屬性,建議你刪除它,直到你知道你需要它。

我想你會想添加到標籤欄控制器這樣之前,你的RSS視圖(VC2?)添加到導航控制器:

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

,並刪除這一行:

[window addSubview:[navigationController view]]; 

祝你好運!

編輯闡述了一點點更多:

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]; 
+0

哦男人太感謝你了! :-) – stepik21 2013-02-16 18:55:47