这是我的代码,在我的应用中,我为UITableView中的每个单元格使用了自定义UITableViewCell,并在“ heightForRowAtIndexPath”中计算了单元格的高度,但是如果我使用“ dequeueReusableCellWithIdentifier”,则在滚动表格视图时该单元格会重叠。 当不使用“ dequeueReusableCellWithIdentifier”时问题就消失了。 不知道为什么会发生这个问题?
实际上,我想知道是否不使用“ dequeueReusableCellWithIdentifier”创建单元格,如果tableview显示很多单元格,是否会引起任何内存问题?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"threadCell";
SYGBBSTableViewCell * cell=nil;
//if I comment below line code , the cell overlap issue solved
cell = (SYGBBSTableViewCell*) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[SYGBBSTableViewCell alloc] initMessagingCellWithReuseIdentifier:cellIdentifier];
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
-(void)configureCell:(SYGBBSTableViewCell*)cell atIndexPath:(NSIndexPath *)indexPath {
SYGBBSTableViewCell* ccell = (SYGBBSTableViewCell*)cell;
...
cell.content.text=content;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath;
{
/// Here you can set also height according to your section and row
NSDictionary* thread = [MyGoController getBBSThreadAtIndex:indexPath.row];
int height = [SYGBBSTableViewCell cellHeightForThreadAt:thread];
return height;
}