Ios 使用UITableViewCellStyle注册UITableViewCell
我知道我可以将类或NIB文件注册为UITableViewCell。但我想用iOS 6的方式Ios 使用UITableViewCellStyle注册UITableViewCell,ios,uitableview,xcode4,Ios,Uitableview,Xcode4,我知道我可以将类或NIB文件注册为UITableViewCell。但我想用iOS 6的方式 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
如果使用register类或register nib,那么就根本不使用If(!cell)子句,而应该使用dequeueReusableCellWithIdentifier:forIndexPath:而不是您正在使用的。您将获得在nib或类中创建的任何样式。通常,这不是苹果的任何默认样式,而是您自己的自定义样式
如果你只想要苹果公司的一种预定义样式,那么最简单的方法就是在IB中选择该样式并给它一个重用标识符——在这种情况下,你应该注册任何东西,系统会自动从情节提要中获取单元格。你为什么要这样做?如果您使用registerClass,则使用
registerClass是没有意义的,因为它们彼此正交。可能重复: