Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:10:38+00:00 2026-06-02T21:10:38+00:00

I have made simple cocoa touch apps before but I have never used UINavigationControllers,

  • 0

I have made simple cocoa touch apps before but I have never used UINavigationControllers, any advice would be greatly appreciated.

I’m trying to add an array of a list of store names to a UITableView. The UITableView is accessed through a UINavigation controller by a tab on a tab bar.

I have a TabBarController.xib file that holds the tab bar.
I also have a AtoZNavigationController.xib that holds the UINavigationController.
And I have a AtoZTableController.xib file that holds the UITableView.

This is my AppDelegate.h:

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

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) IBOutlet UITabBarController *rootController;
@property (strong, nonatomic) IBOutlet AtoZNavigationController *navController;

@end

The AppDelegate.m

#import "AppDelegate.h"
#import "AtoZNavigationController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize rootController;
@synthesize navController;

#pragma mark -
#pragma mark Application lifecycle

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

[[NSBundle mainBundle] loadNibNamed:@"TabBarController" owner:self options:nil];
  [self.window addSubview:rootController.view];
  self.window.backgroundColor = [UIColor whiteColor];
  [self.window makeKeyAndVisible];

return YES;
}
@end

The AtoZNavigationController.h

#import <UIKit/UIKit.h>

@interface AtoZNavigationController : UINavigationController

@end

The AtoZNavigationController.m

#import "AtoZNavigationController.h"

@interface AtoZNavigationController ()

@end

@implementation AtoZNavigationController

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

The AtoZTableController.h

#import <UIKit/UIKit.h>

@interface AtoZTableController : UITableViewController <UITableViewDelegate,       UITableViewDataSource>
{
    IBOutlet UITableView *AtoZTableView;
    NSMutableArray *AtoZArray;
}

@property (nonatomic, retain) IBOutlet UITableView *AtoZTableView;
@end

The AtoZTableController.h

#import "AtoZTableController.h"

@interface AtoZTableController ()

@end

@implementation AtoZTableController
@synthesize AtoZTableView;

-(id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

 -(void)viewDidLoad
 {
     [super viewDidLoad];

     self.title = NSLocalizedString(@"A to Z", @"An A to Z List of Stores");

     AtoZArray = [[NSMutableArray alloc] init];

    [AtoZArray addObject:@"Apple"];
    [AtoZArray addObject:@"Boots"];
    [AtoZArray addObject:@"Topman"];
}

 -(void)viewDidUnload
{
     [super viewDidUnload];
     // Release any retained subviews of the main view.
     // e.g. self.myOutlet = nil;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 0;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [AtoZArray count];
}

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...

    NSInteger row = [indexPath row];
    cell.textLabel.text = [AtoZArray objectAtIndex:row];
    return cell;
}
#pragma mark - Table view delegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}
@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:10:40+00:00Added an answer on June 2, 2026 at 9:10 pm

    In your AtoZTableController.h, you have a problem.

    The problem is in your ‘tableView:cellForRowAtIndexPath:’ method.
    Here’s what you have:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        // Configure the cell...
    
        NSInteger row = [indexPath row];
        cell.textLabel.text = [AtoZArray objectAtIndex:row];
        return cell;
    }
    

    The problem is that you never handle for a return value of nil from dequeueReusableCellWithIdentifier:CellIdentifier.

    Try this out:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        // What happens if you don't get a cell to use?
        // This is the way to create a new, default UITableViewCell
        if (!cell) {            
            // You can look at the UITableViewCell class reference to see the 4 available styles
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    
        // Configure the cell...
        NSInteger row = [indexPath row];
        cell.textLabel.text = [AtoZArray objectAtIndex:row];
        return cell;
    }
    

    Edit/Update:

    OK, so it’s a little bit difficult to know exactly where your error is, so I’ll set up/describe for you a typical situation (or how I’d do it in your shoes).

    If you create a new app and select the “Tabbed Application” template in Xcode, you get the following method in your app delegate (more or less; I condensed it a little bit and “fixed” Apple’s poor choice to use dot notation):

    Note: I believe the problem you’re having with pushing a new view controller will be fixed below now…End Note

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
        // Override point for customization after application launch.
        UIViewController *vc1 = [[FirstViewController alloc] initWithNibName:@"FirstVC" bundle:nil];
        // New line...
        UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:vc1];
        UIViewController *vc2 = [[SecondViewController alloc] initWithNibName:@"SecondVC" bundle:nil];
        [[self setTabBarController:[[UITabBarController alloc] init]];
        // Change here, too...
        [[self tabBarController] setViewControllers:[NSArray arrayWithObjects:navC, vc2, nil]];
        [[self window] setRootViewController:[self tabBarController]];
        [[self window] makeKeyAndVisible];
        return YES;
    }
    

    This method sets up all you need to launch your app with 2 UIViewControllers created and set as tab 1 and tab 2 inside of a UITabBarController.

    Now, you can make FirstViewController and SecondViewController be whatever you want. For purposes of this question, we’ll assume that you want to alter FirstViewController to host a UITableView, which will push a detail UIViewController when a user selects a row on the screen.

    Requirements
    EITHER FirstViewController must be a subclass of UITableViewController (this is not what the default template provides) OR you must add a UITableView onto FirstViewController’s view and set up all of the connections.

    Let’s assume you’re going to keep FirstViewController as a standard UIViewController subclass and that you’ll add a UITableView onto its view. (I’d probably change it to a UITableViewController subclass, but that might be more confusing at this point.)

    First, in FirstViewController.h, change this:

    @interface MMFirstViewController : UIViewController 
    @end
    

    to this:

    @interface MMFirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
        UITableView *TableView;
    }
    @property (strong, nonatomic) IBOutlet UITableView *TableView;
    @end
    

    Next, in FirstViewController.m, synthesize the TableView property (@synthesize TableView).
    Next, click on FirstViewController.xib in Xcode to have it load up in Interface Builder (I’m assuming here that you’re using Xcode 4).
    Now, drag a UITableView from the controls panel onto your UIViewController’s view.
    Make the following connections in Interface Builder:

    1. Right click on File's Owner and connect the TableView property to the UITableView you dropped on the view of FirstViewController.
    2. Right click on the UITableView and connect BOTH the datasource AND delegate properties to File's Owner.

    Now, the code you posted initializing and populating AtoZArray should work fine. Don’t forget to copy in the 3 UITableView methods you previously had, numberOfSectionsInTableView:, tableView:numberOfRowsInSection: and tableView:cellForRowAtIndexPath:.

    Those steps should get you working and should also let you see where you perhaps went wrong in your setup. Please note, you’ll still have to figure out tableView:didSelectRowAtIndexPath: on your own in order to push in your new UIViewController.

    Here’s a teaser to get you started:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Navigation logic may go here. Create and push another view controller.
        ThirdViewController *detailVC = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
        [[self navigationController] pushViewController:detailVC animated:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a simple plugin with a form but it won't post when
I have made a simple timer but in trying to increase the timers speed
I have made a simple, but relatively computationally complex, UDF that queries a rarely
I have made a simple auction section on my site, and I would like
I have made a few simple apps on android, and thought it was time
Hi, I have made this simple script but I need to have it check
I have made a simple test application for the issue, two winforms each containing
I have made a simple web-page including a couple of static pages, a css
I have made a simple web form in Google app engine where I have
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.