0

I have a UIViewController with a UITableView in it. I now want do fill up this table view with my data from array. But the problem is that it doesn't show anything.

This is my implementation file:

#import "MenuViewController.h"

@implementation MenuViewController
@synthesize menuArray;

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

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.menuArray = [[NSArray alloc] initWithObjects:@"Catalogus",@"Wishlist", nil];
    // Do any additional setup after loading the view from its nib.
}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.menuArray count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell.
    cell.textLabel.text = [self.menuArray objectAtIndex:indexPath.row];

    return cell;
}
@end

This is my header file.

#import <UIKit/UIKit.h>

@interface MenuViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
    NSArray *menuArray;
}
@property (nonatomic,retain) NSArray *menuArray;

@end

And in my Xib file I have both the data source and delegate connected to files owner.

2
  • 1
    and what's the question? Commented Jan 18, 2012 at 10:00
  • Is it the whole header file? If so, you may need to make an 'IBOutlet UITableView *yourTableview;' and connect it in the xib Commented Jan 18, 2012 at 12:10

3 Answers 3

1

Set Delegate and DataSource for your tableView. it will works.

Sign up to request clarification or add additional context in comments.

Comments

0

Where you set up your array, reload the table...

self.menuArray = [[NSArray alloc] initWithObjects:@"Catalogus",@"Wishlist", nil];
[myTable reloadData];

Change 'myTable' to the name of your table, which you will need to add to the header as a variable and connect via IB if you are using it.

1 Comment

I used the same code what @user1155884 has provided. In the nib I had a tableview set to files owner datasource and delegate. It works fine.
0

Check the console if you have any errors and let us know.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.