Привет, я новичок в этом устройстве для iPhone, и у меня есть вопрос о reloadRowsAtIndexPaths.Когда пользователь коснется одной ячейки, он развернется и отобразит кнопки под ней, а повторное нажатие закроет ячейку.Это прекрасно работает при открытии и закрытии ячейки по одной за раз, но у меня есть странная анимация, когда касание ячеек происходит последовательно, например, касание ячейки 1, касание ячейки 2, анимация становится странной.Пожалуйста, смотрите видео, чтобы полностью понять ситуацию и извините за низкое качество.
http://www.youtube.com/watch?v=R28Rmti9wPQ
и вот код для перезагрузки ячеек
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
selectedIndexPath = indexPath;
//close the selected cell if it's open
if(selectedIndex == indexPath.row)
{
selectedIndexPath = nil;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
selectedIndex = -1;
selectedIndexPath = indexPath;
return;
}
//this will reload the previously open cell to avoid it from being recycled
if(selectedIndex >= 0)
{
NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];
}
//now reload the selected cell
if(selectedIndexPath != nil && [selectedIndexPath isEqual:indexPath]) {
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
и воткод для создания cellForRowAtIndexPath.
if(selectedIndexPath != nil && [selectedIndexPath isEqual:indexPath]) {
selectedIndex = indexPath.row;
static NSString *CustomCellIdentifier = @"CustomCell";
CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (customCell == nil) {
customCell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier] autorelease];
}
customCell.locationLabelOutlet.text = [usgsFeeds objectAtIndex:[indexPath row]];
customCell.dateLabelOutlet.text = [pubDateArr objectAtIndex:[indexPath row]];
float thisMag;
thisMag = [(NSNumber *)[magnitudeArr objectAtIndex:[indexPath row]] floatValue];
customCell.magnitudeImageOutlet.image = [self imageForMagnitude:thisMag];
[customCell setSelectionStyle:UITableViewCellSelectionStyleNone];
return customCell;
}
else{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
locationLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 225, 20)] autorelease];
locationLabel.tag = kLocationLabelTag;
locationLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
locationLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:locationLabel];
//and all other views for the cell....