Ios UITableViewCell width始终返回320

Ios UITableViewCell width始终返回320,ios,Ios,Cell width始终返回320,一旦重新加载表格,它将根据设备(iphone/ipad)返回正确的单元格宽度。下面是代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *reuseIdentifier = @"testCell"; UITableViewCell *cell = [tableView dequ

Cell width始终返回320,一旦重新加载表格,它将根据设备(iphone/ipad)返回正确的单元格宽度。下面是代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

NSString *reuseIdentifier = @"testCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];

if(cell == nil)

 {
     cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:reuseIdentifier];

 }    

cell.textLabel.text = @"test";

return cell;

}

可能是因为第一次你的手机是通过

[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:reuseIdentifier];
但在重新加载表格后,您的单元格将通过

[tableView dequeueReusableCellWithIdentifier:reuseIdentifier]
使用“旧”尺寸

为了避免这种情况,请在Interface builder中使用正确的单元标识符,在这种情况下,您甚至可以删除创建单元代码

[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:reuseIdentifier]
单元格将始终从接口生成