Not able to add static UITableViewCell into tableview

假装没事ソ 提交于 2019-12-06 05:43:38

问题


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

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.

Screen shot :

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

Any guidence will be appreciated.

Thanks in advance.


回答1:


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

For that you have 2 option

1st : Use Storyboard to design your TableViewCell.

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];
}

Hope this will help to add cell into XIB.




回答2:


I'm sorry for late answer, if you're using xib layout check this;

Cannot add a PrototypeCell to UITableView inside xib file




回答3:


For this first select your TableView and in the Inspector Window Increase Prototype Cells by 1 as shown in ScreenShot



来源:https://stackoverflow.com/questions/41715537/not-able-to-add-static-uitableviewcell-into-tableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!