<分区>
标签 ios iphone uitableview ios7
我正在尝试创建一个不重复使用单元格的表格 View 。
在
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.delegate = self;
return cell;
}
但是这不会加载我的自定义单元格。但是当我添加 dequeReusableCellWithIdentifier: 时,它工作得很好。但是我不想重复使用电池。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
SignUpUserCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.keyLabel.text = [parameterDictionary objectForKey:@"secondLabel"];
cell.textField.text = [parameterDictionary objectForKey:@"secondField"];
// and some more elements
cell.delegate = self;
return cell;
}
如何使用不可重用的表格单元正确创建表格 View 。我在这里做错了什么??
最佳答案
您确定这是您实际使用的代码吗?
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.delegate = self;
return cell;
}
我问的原因是你没有定义cell
是什么,代码不应该是这样的......
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
SignUpUserCell * cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.delegate = self;
return cell;
}
关于ios - 没有单元格重用的 UITableView 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21797736/