【发布时间】:2013-05-05 06:40:48
【问题描述】:
我在 UITableView 中使用了自定义 UITableViewCell,但问题是在调用 dequeueReusableCellWithIdentifier 时单元格永远不会为零。这是为什么呢?
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"PHResultTableViewCell" bundle: nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:@"MyCell"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PHResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (cell == nil)
{
PackageHolidayItem *obj=[[PackageHolidayItem alloc]init];
obj= [totalArray objectAtIndex:indexPath.row];
cell.packageHolidayItem = obj;
[cell loadRow];
}
return cell;
}
【问题讨论】:
-
你在使用故事板吗?
-
即使你没有注册 nib 并且 dequeueReusableCellWithIdentifier 可以返回 nil,仅在
if (cell == nil) { ... }情况下配置单元格也是错误的。
标签: ios uitableview