我通过单击按钮从 TabbedController 页面启动 UITableView 视图。
UITableView 示例取自 LuisEGarza 在 YouTube 上的优秀 UITableView 示例,我相信它是完美的。代码可以编译,但是当 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