Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用UITableViewCellStyle注册UITableViewCell_Ios_Uitableview_Xcode4 - Fatal编程技术网

Ios 使用UITableViewCellStyle注册UITableViewCell

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

我知道我可以将类或NIB文件注册为UITableViewCell。但我想用iOS 6的方式

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是没有意义的,因为它们彼此正交。可能重复: