Ios UITableView中的问题,无需单元重用
我试图在不重用单元格的情况下创建tableview 在Ios UITableView中的问题,无需单元重用,ios,iphone,uitableview,ios7,Ios,Iphone,Uitableview,Ios7,我试图在不重用单元格的情况下创建tableview 在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellSty
- (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;
}
如何使用不可重用的TableCell正确创建tableview。我做错了什么???需要:
return cell;
不是
你确定这就是你实际使用的代码吗
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.delegate = self;
return 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;
}
为什么不使用强烈推荐且功能强大的可重用单元呢?您的第一个代码块实际上并没有编译,因为没有定义
单元
。所以我猜你说的不对。值得一提的是,我在我的示例项目中声明了cell
,使它能够正常工作,但如果可能的话,你应该重新使用这些单元格。你做错了的是“没有做苹果希望你做的事”。在苹果的世界里,这是一个致命的错误。虽然有时你可以成功,但真正的解决办法是遵循苹果的文档和推荐的技术。事实上,我为我的错误感到抱歉。我已经在代码中正确声明了SignUpUserCell*cell。那么你认为问题是什么?我的代码与这里添加的更正代码相同,它不是简单的单元格。您的SignUpUserCell
看起来像什么?您是否在nib中定义它?不,我使用的是故事板。好的,那么您是否在属性中设置了自定义类名,并且您的标识符是否与您在故事板中输入的内容匹配。如果你展示一些屏幕截图会有帮助吗?正如其他人已经指出的,您应该真正使用可重用的单元
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
SignUpUserCell * cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.delegate = self;
return cell;
}