0

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;

}
Eduard
  • 309
  • 2
  • 12

2 Answers2

1

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];
iphonic
  • 12,615
  • 7
  • 60
  • 107
  • Thank you for your quick reply, I will follow your steps and reply as soon as I'm done! :) – Eduard Apr 10 '14 at 17:55
  • I have tried to follow your steps, but with no luck; on step 2: If I add a UIView Controller - the TableView I add in step 3 will be fullscreen, if I add a UIView I can't connect view to the UIView... sorry for being incapable of following your seemingly easy steps... I have shared my proyect on Dropbox in case you want to see how it looks: https://www.dropbox.com/sh/6iwhcvk5h4hahpc/sjZGqmZfjo – Eduard Apr 10 '14 at 18:22
  • @Ockie Check I have modified your code here https://dl.dropboxusercontent.com/u/78701794/stackoverflow_modified.zip though I couldn't test dues to some reason. One thing why aren't you using xib to design your view ? It would be easier.. – iphonic Apr 11 '14 at 04:26
  • testing your changes but somehow I'm just getting a black screen... I don't know why you couldn't test, perhaps because of dropbox chooser? will continue trying to get this to work as needed... will share result as soon as I'm done – Eduard Apr 11 '14 at 16:57
0

Why don't you create the desired structure in one nib itself? Create a nib with view controller. On the nib place your buttons and tableview as per your layout. Interface builder is intended to reduce your coding effort when it comes to design so use it. Make sure to make your new view controller as the root controller in app delegate.

Shivam Mishra
  • 137
  • 1
  • 12
  • When I started working on the proyect doing everything programmatically seemed to be easier to me (as its my first proyect for iOS) and I'm more used to making things programmatically than with interface builder :) I see now I was wrong, however with @iphonic help I hope to get stuff working without needing to change too much :) – Eduard Apr 10 '14 at 18:08