Edward Hasted
Edward Hasted

Reputation: 3433

Xcode 4.3 UITableView Blank

I'm firing up a UITableView View from a TabbedController page by clicking on a button.

The UITableView example was taken from LuisEGarza's excellent UITableView example on YouTube and to my belief is line perfect. The code compiles, but when the UITableView page comes up it is blank. Is this an issue with the TabbedController or have I done something else wrong?

Below are the sample .m and .h files.

//
//  SolarResultsTableViewController.h
//  Solar
//
//  Created by Edward Hasted on 08/05/2012.
//  Copyright (c) 2012 EHC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SolarResultsTableViewController : UIViewController  <UITableViewDelegate, UITableViewDataSource> {

    NSArray *tableData;
    // IBOutlet UILabel *rowLabel;

}

@property (nonatomic, retain) NSArray *tableData;

@end




//
//  SolarResultsTableViewController.m
//  Solar
//
//  Created by Edward Hasted on 08/05/2012.
//  Copyright (c) 2012 EHC. All rights reserved.
//

#import "SolarResultsTableViewController.h"

@implementation SolarResultsTableViewController 
@synthesize tableData;

- (void)viewDidLoad
{
    tableData = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", @"D", nil];
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - TableView Data Source methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    // rowLabel.text = [NSString stringWithFormat:@"%d", count];
    return [tableData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = nil;
    cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
    if (cell == nil)
            { 
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
            }
    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];            
    return cell;
}

- (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.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

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

@end

Upvotes: 1

Views: 1199

Answers (1)

Prasad G
Prasad G

Reputation: 6718

Implement (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView method

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

I hope it will be helpful to you.

Upvotes: 2

Related Questions