我有搜索网站,了解如何创建自定义表格视图(因为我想隐藏导航栏为特定视图),我正在按照每一步。但是,我的结果不显示表格。自定义TableViewController,不显示
这里是我的.h文件
#import <UIKit/UIKit.h>
@interface HallFameControllerViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>{
NSArray *leaders;
}
@property (strong, nonatomic) NSArray *leaders;
@end
和我的.m文件
#import "HallFameControllerViewController.h"
@interface HallFameControllerViewController()
@end
@implementation HallFameControllerViewController
@synthesize leaders;
- (void)viewDidLoad
{
[super viewDidLoad];
leaders = [NSArray arrayWithObjects:@"Player #1", @"Player #2", @"Player #3", nil];
}
- (void) viewDidUnload{
self.leaders = nil;
}
- (void) viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [leaders count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell.
cell.textLabel.text = [self.leaders objectAtIndex: [indexPath row]];
return cell;
}
@end
在我的故事板,我创建了一个视图控制器和里面我有1个标签和1周的TableView。我为我的ViewController设置了自定义类为“HallFameControllerViewController”,数据源,表视图的代理也设置为“HallFameControllerViewController”。结果,标签在那里但没有表格。
我有一些printf()语句在侧.m文件,viewDidLoad()执行,但cellForRowAtIndexPath()不!
我在做什么错在这里?另外,cellIdentifier是什么,为什么设置为“Cell”(自动)?
在此先感谢。
已复制,已答复x次。 numberOfSectionsInTableView = 1 –
@ Daij-Djan有更多的问题,而不是错误的部分数量。 – rmaddy