无法将静态UITableViewCell添加到tableview中 [英] Not able to add static UITableViewCell into tableview

查看:94
本文介绍了无法将静态UITableViewCell添加到tableview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我是IOS开发的新手,我正在尝试将 CustomeCell 添加到 tableView 中,但我无法添加它来自图书馆。

As I am new in IOS development I am trying to add CustomeCell into tableView but I can not add it from library.

我正在做的只是在我的 ViewController中拖动 TableView 而不是拖动 tableview 单元格,但在 ViewController 的视图下添加为额外视图能够将它添加到tableview中。

What I am doing is just drag TableView in my ViewController and than drag tableview cell in it but its added as extra view under ViewController 's view not able to add it into tableview.

我知道怎样才能通过拖放添加单元格。

I am stuck here any idea how can I add cell by drag and drop.

屏幕截图:

我知道如何通过编码添加单元格,但是通过代码添加每个东西的过程非常漫长。

I know how to add cell by coding but its very lengthy process to add every thing by code.

任何指导都将不胜感激。

Any guidence will be appreciated.

提前致谢。

推荐答案

根据我的经验,你无法将自定义单元格添加到 TableView 当您在 XIB 中使用或编辑 ViewController / View / Cell 时。

As per my exprience you can not add Custom Cell into TableView while you are using or editing your ViewController/View/Cell into XIB.

为此您有2个选项

第1名使用Storyboard设计 TableViewCell

1st : Use Storyboard to design your TableViewCell.

第二名:使用 XIB 创建新的自定义单元格并将其加载到您的 tableView 中,其中 NIB 如下所示。

2nd : Create new custom cell with XIB and load it into your tableView with NIB name like below.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
if (cell == nil) {
   // Create a temporary UIViewController to instantiate the custom cell.
   NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
   // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
   cell = [topLevelObjects objectAtIndex:0];
}

希望这有助于将单元格添加到XIB中。

Hope this will help to add cell into XIB.

这篇关于无法将静态UITableViewCell添加到tableview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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