ios 7 dequeueReusableCellWithIdentifier:forIndexPath method - does it need registerClass method

六月ゝ 毕业季﹏ 提交于 2019-12-23 12:09:30

问题


I am using ios 7.

Quick question. I have a working program that uses dequeueReusableCellWithIdentifier:forIndexPath to display cells with two different prototypes. I never used the UITableView registerClass method.

Does this mean that I am not reusing the cells? My thinking is that this is not the case (as I have fixed bugs before in this app which were related to cells retaining prior states).

If I actually use registerClass now (in viewDidLoad for the tableVieW), my data is not being shown - any ideas why?

Thank you!

UPDATE I add the registerClass code in viewDidLoad as follows:

[self.tableView registerClass:[ProtoCell1 class] forCellReuseIdentifier:@"proto1"];
[self.tableView registerClass:[ProtoCell2  class] forCellReuseIdentifier:@"proto2"];

回答1:


If the cell is created using prototypes within a storyboard it is not necessary to register the class.

Using

 registerClass:forCellWithReuseIdentifier

will prevent your view from rendering if it was already declared in Interface Builder. If you registered your cell identifier in storyboard and you are using

  dequeueReusableCellWithReuseIdentifier: 

then you should be reusing cells



来源:https://stackoverflow.com/questions/19304528/ios-7-dequeuereusablecellwithidentifierforindexpath-method-does-it-need-regis

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