我遇到了一个非常奇怪的错误,我无法弄清楚,我现在真的需要一些帮助。基本上,tableView 有三个 UITableViewCell 子类,它们都有自己的原型单元格,并出现在自己的部分中。但是第三部分中的原型也出现在第二部分中。奇怪的是,在将一些 NSLogs 放入我的代码后,显示在第二部分(应该在第三部分)中的单元格是 UITableViewCell 的正确子类,但另一个原型的内容正在显示. 我不知道为什么会这样。我已经检查以确保原型是正确的子类,并且标识符都是正确的,而且它们是正确的。有没有人遇到过这个问题?提前抱歉我的cellForRowAtIndexPath:
方法需要多长时间:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WaveDetailCell *waveDetails;
ActionsCell *actions;
CommentCell *comments;
id cellToReturn;
if (self.hasAgrees || self.hasComments)
{
switch (indexPath.section)
{
case 0:
{
waveDetails = [tableView dequeueReusableCellWithIdentifier:WaveDetailCellIdentifier forIndexPath:indexPath];
if ([waveDetails.waveLabel respondsToSelector:@selector(setAttributedText:)])
{
NSString *name = self.currentWaveObject.wavedToUserID;
NSString *fullWaveString = [name stringByAppendingString:self.currentWaveObject.waveString];
NSRange range = [fullWaveString rangeOfString:self.currentWaveObject.wavedToUserID];
UIFont *font = [UIFont fontWithName:HelveticaMedium size:16.0f];
NSDictionary *attrs = @{NSFontAttributeName: font};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fullWaveString];
[attributedString addAttributes:attrs range:range];
[waveDetails.waveLabel setAttributedText:attributedString];
}
waveDetails.wavedByNameLabel.text = self.currentWaveObject.wavedByUserID;
waveDetails.timestampLabel.text = self.currentWaveObject.creationDate;
//round the corners of the imageview
[self setCornerRadiusForImageView:waveDetails.profilePicImageView withRadius:CGSizeMake(4.0f, 4.0f)];
[self setCornerRadiusForImageView:waveDetails.waverProfileImageView withRadius:CGSizeMake(2.0f, 2.0f)];
cellToReturn = waveDetails;
}
break;
case 1:
{
if (self.hasAgrees)
{
//create agrees cell
}
else
{
actions = [tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
}
case 2:
{
if (self.hasAgrees)
{
//if there are agrees, and no comments, then the last section should be the actions cell
actions = [tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
else
{
//there are comments, and no agrees
comments = [tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier forIndexPath:indexPath];
CommentObject *comment = [self.currentWaveObject.commentsArray objectAtIndex:indexPath.row];
comments.userNameLabel.text = comment.commenterID;
comments.commentLabel.text = comment.commentText;
comments.timeStampLabel.text = comment.timeStamp;
[self setCornerRadiusForImageView:comments.userImageView withRadius:CGSizeMake(3.0f, 3.0f)];
cellToReturn = comments;
}
}
default:
break;
}
}
else if (self.hasComments && self.hasAgrees)
{
switch (indexPath.section)
{
case 0:
{
waveDetails = (WaveDetailCell *)[tableView dequeueReusableCellWithIdentifier:WaveDetailCellIdentifier forIndexPath:indexPath];
if ([waveDetails.waveLabel respondsToSelector:@selector(setAttributedText:)])
{
NSString *name = self.currentWaveObject.wavedToUserID;
NSString *fullWaveString = [name stringByAppendingString:self.currentWaveObject.waveString];
NSRange range = [fullWaveString rangeOfString:self.currentWaveObject.wavedToUserID];
UIFont *font = [UIFont fontWithName:HelveticaMedium size:16.0f];
NSDictionary *attrs = @{NSFontAttributeName: font};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fullWaveString];
[attributedString addAttributes:attrs range:range];
[waveDetails.waveLabel setAttributedText:attributedString];
}
waveDetails.wavedByNameLabel.text = self.currentWaveObject.wavedByUserID;
waveDetails.timestampLabel.text = self.currentWaveObject.creationDate;
//round the corners of the imageview
[self setCornerRadiusForImageView:waveDetails.profilePicImageView withRadius:CGSizeMake(4.0f, 4.0f)];
[self setCornerRadiusForImageView:waveDetails.waverProfileImageView withRadius:CGSizeMake(0.5f, 0.5f)];
cellToReturn = waveDetails;
}
break;
case 1:
{
//create agrees cell
}
break;
case 2:
{
actions = (ActionsCell *)[tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
break;
case 3:
{
comments = (CommentCell *)[tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier forIndexPath:indexPath];
CommentObject *comment = [self.currentWaveObject.commentsArray objectAtIndex:indexPath.row];
comments.userNameLabel.text = comment.commenterID;
comments.commentLabel.text = comment.commentText;
comments.timeStampLabel.text = comment.timeStamp;
[self setCornerRadiusForImageView:comments.userImageView withRadius:CGSizeMake(2.0f, 2.0f)];
cellToReturn = comments;
}
break;
default:
break;
}
}
else
{
if (indexPath.row == 0)
{
waveDetails = (WaveDetailCell *)[tableView dequeueReusableCellWithIdentifier:WaveDetailCellIdentifier forIndexPath:indexPath];
if ([waveDetails.waveLabel respondsToSelector:@selector(setAttributedText:)])
{
NSString *name = self.currentWaveObject.wavedToUserID;
NSString *fullWaveString = [name stringByAppendingString:self.currentWaveObject.waveString];
NSRange range = [fullWaveString rangeOfString:self.currentWaveObject.wavedToUserID];
UIFont *font = [UIFont fontWithName:HelveticaMedium size:16.0f];
NSDictionary *attrs = @{NSFontAttributeName: font};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fullWaveString];
[attributedString addAttributes:attrs range:range];
[waveDetails.waveLabel setAttributedText:attributedString];
}
waveDetails.wavedByNameLabel.text = self.currentWaveObject.wavedByUserID;
waveDetails.timestampLabel.text = self.currentWaveObject.creationDate;
//round the corners of the imageviews
[self setCornerRadiusForImageView:waveDetails.profilePicImageView withRadius:CGSizeMake(4.0f, 4.0f)];
[self setCornerRadiusForImageView:waveDetails.waverProfileImageView withRadius:CGSizeMake(0.5f, 0.5f)];
cellToReturn = waveDetails;
}
else
{
actions = (ActionsCell *)[tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
}
return cellToReturn;
}