我有一个简单的MainWindow文件,由Interface Builder在黑色背景下创建。在这个普通视图中,我从上到下添加了一个小视图(300x100),一个textLabel和几个按钮。
在MainApplication.h中,我定义了:
IBOutlet RoundRectView * smallView; IBOutlet UILabel *标签;
在MainApplication.h中,我已经@synthesized这些变量并使用:
[label setText:@“Test”];
我可以在屏幕上看到所有内容并且效果很好。
现在我的问题:
我想在我的小白色视图中添加一个包含两行的表格,我所做的是:
@interface IncomeExpenseController: 的UITableViewController {IBOutlet UITableView * smallTable; NSArray的 *内容; }
@property(非原子,保留) UITableView * smallTable; @属性 (非原子,保留)NSArray *内容;
@end
@synthesize smallTable; @合成 内容;
(void)viewDidLoad { [super viewDidLoad]; content = [[NSArray alloc] initWithObjects:@“Item1”,@“Item2”, 零]; }
(NSInteger的)numberOfSectionsInTableView:(UITableView的 *)tableView { //返回部分的数量。 返回0; }
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { //返回节中的行数。 返回2; }
//自定义表格的外观 查看单元格。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] 自动释放]; } NSLog(@“在单元格内”);
// Configure the cell... cell.textLabel.text = [content
objectAtIndex:indexPath.row];
return cell; }
现在在Interface Builder中,我将UITableView拖放到白色小视图中,然后拖放一个Table View Controller和File Owner's窗口,然后进行以下连接:
Table View Controller到tableController的类
网点: DataSource和委托给我的表控制器
引用Outlets: customTable和View to my Table Controllers
当我执行时,我可以看到表视图的行但没有内容,我也看不到NSLog,但是如果我在viewDidLoad中放置一个NSLog,我可以看到它。
我真的很新(2天)就可以了,任何帮助都会非常感激。
谢谢!
答案 0 :(得分:0)
解决。
首先,TableView被分组,所以我必须返回几乎一个部分。 其次,从Interface Builder,我不得不将表中的“视图”链接到我的外部控制器。
现在它完美无缺。