У меня очень странная ошибка, которую я не могу понять, мне действительно нужна помощь прямо сейчас. В принципе, tableView имеет три подкласса UITableViewCell, которые имеют собственную ячейку прототипа и отображаются в своем разделе. Но прототип, который находится в третьем разделе, также появляется во втором разделе. Странная часть заключается в том, что после помещения некоторых NSLogs в мой код ячейка, которая отображается во втором разделе раздела (которая должна быть в третьем разделе), является правильным подклассом UITableViewCell, но содержимое из другого прототипа появляется , Я понятия не имею, почему это происходит. У меня есть проверка, чтобы убедиться, что прототипы имеют правильный подкласс, а идентификаторы - все правильно, и они есть. Кто-нибудь сталкивался с этой проблемой раньше? К сожалению, заранее, как долго мой cellForRowAtIndexPath:
метода:UITableView загружает неправильную ячейку прототипа из раскадровки
- (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;
}