静态单元格:不显示内容 [英] Static cells: Content does not appear

查看:120
本文介绍了静态单元格:不显示内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想拥有一个包含项目的静态表视图。我使用Xcode 4.2和storyboard来完成这项任务。所以我用tableViewController(子类UITableViewController)创建了一个TableView。我将内容定义为静态单元格和样式分组。

I simply want to have a static table View with items in it. I used Xcode 4.2 with storyboard for this task. So I created a TableView with a tableViewController (subclass UITableViewController). I defined the content as "Static Cells" and style "Grouped".

之后我把一些标签和我想要的所有对象放在那些单元格中。我在tableViewController中创建了Outlets:

After that I put some lables and all those objects I want to have in those cells. I created Outlets in the tableViewController:

#import <UIKit/UIKit.h>

@interface tableviewcontroller : UITableViewController
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmented;
@property (weak, nonatomic) IBOutlet UIImageView *imageview;
@property (weak, nonatomic) IBOutlet UITextView *text;

@end

在单元格标签中添加一些内容:

put some content in the cell-label:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.label1.text = @"This is a title";
    self.label2.text = @"Annika";
    self.imageview.image = [UIImage imageNamed: @"picture.jpg"];
}

构建并运行后,它不会显示任何元素。 .. 我做错了什么?

After build and run, it doesn't show me any of the elements... what did I do wrong?

左:在故事板中,右:在模拟器中。

Left: In storyboard, right: In the simulator.

推荐答案

对于静态表视图,不得实现任何数据源方法。 UITableViewController的基本实现有自己的这些方法版本,通过读取storyboard文件返回相应的内容。这些方法是提供表格内容的方法,例如, numberOfRows,numberOfSections,heightForRow,cellForRow等等。

For static table views, you must not implement any of the datasource methods. The base implementation of UITableViewController has its own versions of these methods which return the appropriate content by reading the storyboard file. The methods are those which provide the table content, e.g. numberOfRows, numberOfSections, heightForRow, cellForRow and so forth.

在你的情况下,你实现了 tableView:cellForRowAtIndexPath:并且每次都返回空单元格。这意味着你的细胞大小是正确的,但内容已经消失。

In your case, you'd implemented tableView:cellForRowAtIndexPath: and returned empty cells each time. This meant the size of your cells was correct, but the content was gone.

此外,静态表视图中的内容出口都不会设置,直到之后 [super viewWillAppear:动画] 已被调用。它们仍然是viewDidLoad的nil,你在那里调用它们,因为表视图在那时没有询问它的任何内容。

Also, none of the outlets to content in your static table view will be set until after [super viewWillAppear:animated] has been called. They will still be nil at viewDidLoad, where you are calling them from, because the table view hasn't asked for any of it's content at that point.

这篇关于静态单元格:不显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆