我通过单击按钮从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
答案 0 :(得分:2)
实施(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
我希望它会对你有所帮助。