iOS - 带有表视图和子视图的选项卡式应用程序

时间:2013-02-16 18:38:21

标签: uitableview subview tabbed-view

我有一个问题。在我的应用程序(它是标签式样式)中,我有一个带有一些文本的viewcontroller,第二个有表视图(RSS阅读器)。当我只有RSS并且它被设置为单视图应用程序时,子视图表单rss可以工作,但是当我设置选项卡式应用程序并在表格视图中单击某些帖子时,子视图没有显示...有人可以帮我吗?

以下是我的代码:

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 个答案:

答案 0 :(得分:0)

从dealloc,我看到你没有使用弧线。 你有一些内存泄漏;请务必在vc1中发布vc2didFinishLaunchingWithOptions,标签栏控制器会保留它们。

您可能不需要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];