2

我正在尝试更改xcode 4上的选项卡式应用程序以合并没有情节提要的导航控制器。第一个选项卡包含一个表格。这是需要导航的。

这是 FirstViewController.h

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController <UITableViewDelegate,     UITableViewDataSource> {
IBOutlet UITableView *storeDetailsTable;
}

@property (nonatomic, retain) UITableView *storeDetailsTable;
@property (nonatomic, strong) NSDictionary *resultData;
@property (nonatomic, strong) NSMutableArray *populatedStoreArray;
@property (nonatomic, strong) NSMutableArray *images;


@end

这是 NavController.h:

 #import <UIKit/UIKit.h>

    @interface NavController : UINavigationController

    @property (nonatomic,retain) IBOutlet UINavigationController * navController;

    @end

因此,我将 NavController 用作 UIViewControllerSubclass,然后将其更改为上述内容。

AppDelegate.h:

#import <UIKit/UIKit.h>
@class NavController;

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> {
    IBOutlet NavController *navController;
}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@property (strong, nonatomic) IBOutlet NavController *navController;

@end

和 AppDelegate.m:

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "NavController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize navController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    navController = [[NavController alloc] initWithNibName:@"NavController" bundle:nil];
//        UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, viewController2, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

现在,当我构建并运行它时,我看到了 2 个选项卡。但是第一个选项卡只是一个描绘导航控制器的空白黑屏,但没有应有的表格视图。

有什么我错过的吗?

谢谢..

4

1 回答 1

3

在您的代码中,我看不到您正在初始化 FirstViewController 类并使其为 NavController 所知。NavController 需要使用 RootViewController 进行初始化,例如:

NavController *myNavController = [[NavController alloc] initWithRootViewController:yourFirstViewController];

查找更多信息的好地方是:http: //developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

于 2012-09-03T17:53:08.447 回答