MainStoryBoard 中UITableView Cell的重用

来源:互联网 发布:linux中没有yum命令 编辑:程序博客网 时间:2024/05/02 00:09

问题: 使用MainStoryBoard定义Cell 使用后显示空白Cell,定义的视图没有显示.

解答: 使用惯了xib定义的cell 之后在viewdidload 中习惯性的注册cell,在storyBoard中不需要注册(不需要代码注册)只需要在方法

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中添加

    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
原因是在MainstoryBoard中 我们已经对自定义的Cell 进行了注册



如图,我们在Cell的属性界面对其进行了注册,identifier 为"TableViewCell"

不需要在 ViewDidLoad 对其进行注册了,如果进行注册的话,则对xcode来说你引用的不是storyboard上的定义的Cel,而是你创建的空Cell类了,所以显示为空白.

0 0