2012-05-09 2 views
1

Я запускаю UITableView View с страницы TabbedController, нажимая на кнопку.Xcode 4.3 UITableView Blank

Пример UITableView был взят из превосходного примера UITableView от LuisEGarza на YouTube, и моя убежденность в том, что линия идеальна. Код компилируется, но когда появляется страница UITableView, она пуста. Это проблема с TabbedController или я сделал что-то еще неправильно?

Ниже приведены образцы .m и .h файлов.

// 
// 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 
+0

Вы не инициализируете и не добавляете вид таблицы? – rishi

+0

Правильно ли вы подключили свой делегат tableView и свойства dataSource к контроллеру? (Можно сказать, поставив NSLog в один из методов dataSource, если они не вызваны, тогда ваш tableView не подключен). А также, где ваш tableView instanciated? В XIB? – Cyrille

ответ

2

Реализовать (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView метод

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

    return 1; 
} 

Я надеюсь, что это будет полезно для вас.