我有搜索網站,瞭解如何創建自定義表格視圖(因爲我想隱藏導航欄爲特定視圖),我正在按照每一步。但是,我的結果不顯示錶格。自定義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