我正在尝试制作一个简单的 iOS 应用程序,它使用 UINavigationController 两个 ViewController 和一个 UITableView 来显示列表。问题是该表拒绝显示来自 NSArray 的数据。正如您在图片中看到的那样,所有代表都已设置好。

如果我为 ViewController 创建一个 xib 文件,每件事都有效,但如果我可以在 Storyboard 中再拖动一个 ViewController 并将它的类链接到我的 ItemListViewController,我不需要一个 xib 文件,如您在第一张图片中看到的那样。
项目列表视图控制器.h
#进口
@interface ItemListViewController : UIViewController{
NSMutableArray *tblDataSource;
IBOutlet UITableView *tblSimpleTable;
}
@property (assign) NSMutableArray *tblDataSource;
@property(保留)IBOutlet UITableView *tblSimpleTable;
@结尾
项目列表视图控制器.m
#import "ItemListViewController.h"
@interface 项目列表视图控制器 ()
@结尾
@implementation ItemListViewController
@synthesize tblDataSource,tblSimpleTable;
- (id)initWithNibName:(NSString *)nibNameOrNil 包:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
// 自定义初始化
}
回归自我;
}
- (void)viewDidLoad
{
[超级视图DidLoad];
// 加载视图后做任何额外的设置。
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg.png"]];
self.tblSimpleTable.backgroundColor = 背景;
[背景发布];
NSArray * data = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut ”,@“星巴克咖啡”,@“蔬菜咖喱”,@“鸡蛋方便面”,@“叉烧面”,@“日本猪肉面”,@“绿茶”,@“泰式虾饼” ,@“愤怒的小鸟蛋糕”,@“火腿芝士帕尼尼”,无];
[tblDataSource setArray:数据];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// 处理所有可以重新创建的资源。
}
#pragma mark - 表格视图数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// 返回部分的数量。
返回0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// 返回节中的行数。
NSLog(@"@%d",[tblDataSource 计数]);
返回 [tblDataSource 计数];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
静态 NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(细胞 == 零){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// 配置单元格...
UIImage *placeholder = [UIImage imageNamed:@"icon.png"];
[cell.imageView setImage:placeholder];
cell.textLabel.text = [tblDataSource objectAtIndex:indexPath.row];
返回单元格;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"点击行@%d",indexPath.row);
}
@结尾
如果有人能指出我正确的方向,我做错了什么。