iosuiviewtableviewnib

set current tableview inside new uiview


I've been making an App completely programmatically, but I would like to add some more buttons etc.

Currently my main view is a full-screen TableView. I would like to load a UIView (from a NIB) which has some buttons / labels and my curreny TableView in the middle (full width) with sort of a header and footer with my buttons / labels.

(Since I suspect that changed need to be made here...) My AppDelegate currently has the following code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    AFViewController *viewController = [[AFViewController alloc] initWithStyle:UITableViewStylePlain];
    //AFViewController *viewController = [[AFViewController alloc] initWithNibName:@"mainView" bundle:nil];
    self.viewController = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = self.viewController;

    [self.window makeKeyAndVisible];
    return YES;

}

Solution

  • You need to create a UIViewController instead of UITableViewController. You can easily do in your current AFViewController which actually a UITableViewController, just follow these steps

    1. Open AFViewController.h change UITableViewController to UIViewController.
    2. Then open AFViewController.xib and add a UIView from controls.
    3. Drag UITableView inside UIView.
    4. Right click File Owner connect view to the UIView and create IBOutlet for the UITableView inside the UIView.

    Thats it you are ready to go.. And at last..

    AFViewController *viewController = [[AFViewController alloc] initWithNibName:@"AFViewController" bundle:nil];