2016-08-29 391 views
0

我正在調試應用程序,並有一個小故障。我在應用程序和互聯網上查找它,但沒有找到任何東西。iOS應用程序故障

您可以從以下

enter image description here

它看起來像下面爲短的時間間隔達到毛刺。

enter image description here

我的代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
if (indexPath.item == 0) { 
    HGOtherUserTopInformationCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForTopInfoCellProfile forIndexPath:indexPath]; 
    cell.user = [HGUser currentUser]; 
    cell.amIFollowing = false; 
    cell.delegate = self; 
    cell.viewController = self; 
    return cell; 
}else{ 
    if (indexPath.item % 2 != 0) { 
     HGSeperatorCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForSeperatorCellProfile forIndexPath:indexPath]; 
     cell.backgroundColor = [UIColor lightGrayColor]; 
     return cell; 
    }else{ 
     HGActivity * activity = self.profileActivities[(indexPath.item - 2)/2]; 
     if ([activity.activityType isEqualToString:kActivityKeyUserPublishedResponse]) { 
      // Response 
      HGResponse * response = activity.response; 
      if ([response.mediaType isEqualToString:@"Photo"]) { 
       HGOtherUserPhotoCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForPhotoCellProfile forIndexPath:indexPath]; 
       cell.response = response; 
       cell.indexPath = indexPath; 
       cell.baseDelegate = self; 
       if (userLikedResponses) { 
        if ([userLikedResponses containsObject:response.objectId]) { 
         cell.liked = true; 
        }else{ 
         cell.liked = false; 
        } 
       } 
       cell.viewController = self; 
       if (joinedChallenges) { 
        bool joined = false; 
        for (HGActivity * joinedChallengeActivity in joinedChallenges) { 
         if ([joinedChallengeActivity.challenge.objectId isEqualToString:response.challenge.objectId]) { 
          joined = true; 
          break; 
         } 
        } 
        cell.joined = joined; 
       }else{ 
        cell.joined = false; 
       } 
       return cell; 
      }else if ([response.mediaType isEqualToString:@"Video"]) { 
       HGOtherUserVideoCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForVideoCellProfile forIndexPath:indexPath]; 
       cell.response = response; 
       cell.indexPath = indexPath; 
       cell.baseDelegate = self; 
       if (userLikedResponses) { 
        if ([userLikedResponses containsObject:response.objectId]) { 
         cell.liked = true; 
        }else{ 
         cell.liked = false; 
        } 
       } 
       if (indexPath.item == 2) { 
        [cell playMuted]; 
       } 
       cell.viewController = self; 
       if (joinedChallenges) { 
        bool joined = false; 
        for (HGActivity * joinedChallengeActivity in joinedChallenges) { 
         if ([joinedChallengeActivity.challenge.objectId isEqualToString:response.challenge.objectId]) { 
          joined = true; 
          break; 
         } 
        } 
        cell.joined = joined; 
       }else{ 
        cell.joined = false; 
       } 
       return cell; 
      }else{ 
       HGOtherUserMedialessCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForMedialessCellProfile forIndexPath:indexPath]; 
       cell.response = response; 
       cell.indexPath = indexPath; 
       cell.baseDelegate = self; 
       if (userLikedResponses) { 
        if ([userLikedResponses containsObject:response.objectId]) { 
         cell.liked = true; 
        }else{ 
         cell.liked = false; 
        } 
       } 
       cell.viewController = self; 
       if (joinedChallenges) { 
        bool joined = false; 
        for (HGActivity * joinedChallengeActivity in joinedChallenges) { 
         if ([joinedChallengeActivity.challenge.objectId isEqualToString:response.challenge.objectId]) { 
          joined = true; 
          break; 
         } 
        } 
        cell.joined = joined; 
       }else{ 
        cell.joined = false; 
       } 
       return cell; 
      } 
     }else{ 
      // Challenge 
      HGChallenge * challenge = activity.challenge; 
      if ([challenge.mediaType isEqualToString:@"Photo"]) { 
       HGOtherUserPhotoCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForPhotoCellProfile forIndexPath:indexPath]; 
       cell.challenge = challenge; 
       cell.indexPath = indexPath; 
       cell.baseDelegate = self; 
       if (userLikedChallenges) { 
        if ([userLikedChallenges containsObject:challenge.objectId]) { 
         cell.liked = true; 
        }else{ 
         cell.liked = false; 
        } 
       } 
       cell.viewController = self; 
       if (joinedChallenges) { 
        bool joined = false; 
        for (HGActivity * joinedChallengeActivity in joinedChallenges) { 
         if ([joinedChallengeActivity.challenge.objectId isEqualToString:challenge.objectId]) { 
          joined = true; 
          break; 
         } 
        } 
        cell.joined = joined; 
       }else{ 
        cell.joined = false; 
       } 
       return cell; 
      }else if ([challenge.mediaType isEqualToString:@"Video"]) { 
       HGOtherUserVideoCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForVideoCellProfile forIndexPath:indexPath]; 
       cell.challenge = challenge; 
       cell.indexPath = indexPath; 
       cell.baseDelegate = self; 
       if (userLikedChallenges) { 
        if ([userLikedChallenges containsObject:challenge.objectId]) { 
         cell.liked = true; 
        }else{ 
         cell.liked = false; 
        } 
       } 
       if (indexPath.item == 2) { 
        [cell playMuted]; 
       } 
       cell.viewController = self; 
       if (joinedChallenges) { 
        bool joined = false; 
        for (HGActivity * joinedChallengeActivity in joinedChallenges) { 
         if ([joinedChallengeActivity.challenge.objectId isEqualToString:challenge.objectId]) { 
          joined = true; 
          break; 
         } 
        } 
        cell.joined = joined; 
       }else{ 
        cell.joined = false; 
       } 
       return cell; 
      }else{ 
       HGOtherUserMedialessCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierForMedialessCellProfile forIndexPath:indexPath]; 
       cell.challenge = challenge; 
       cell.indexPath = indexPath; 
       cell.baseDelegate = self; 
       if (userLikedChallenges) { 
        if ([userLikedChallenges containsObject:challenge.objectId]) { 
         cell.liked = true; 
        }else{ 
         cell.liked = false; 
        } 
       } 
       cell.viewController = self; 
       if (joinedChallenges) { 
        bool joined = false; 
        for (HGActivity * joinedChallengeActivity in joinedChallenges) { 
         if ([joinedChallengeActivity.challenge.objectId isEqualToString:challenge.objectId]) { 
          joined = true; 
          break; 
         } 
        } 
        cell.joined = joined; 
       }else{ 
        cell.joined = false; 
       } 
       return cell; 
      } 
     } 
    } 
} 
+0

滾動後發生? –

+1

您不是以正確的方式「重用」tableview單元格。 – rptwsthi

+1

顯示一些代碼? –

回答

0

有關於reloadData的問題。舊代碼就像下面

[weakSelf.collectionView reloadData]; 

我改成了這樣:

[weakSelf.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; 

而且它解決了我的問題。文本中沒有更多的小故障,但圖片上出現了故障。但它看起來很酷,所以我保持它:)

0

如果你是顯示根據條件,那麼你必須正確地重用實現代碼如下cells.create共同UITableViewCell類,許多定製單元(在你的情況例如:HGCell)爲UI,你可以根據你的需要創建很多的筆尖(例如:HGOtherUserTopInformationCell,HGSeperatorCell ...)。下面的代碼顯示了處理許多單元格的示例。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *cellIdentifier = [NSString stringWithFormat:@"Cell%ld",(long)indexPath.row]; 

    NSString *nibName; 

    if(indexPath.item == 0) 
    { 
     nibName = @"HGOtherUserTopInformationCell"; 
    } 
    else 
    { 
     if (indexPath.item % 2 != 0) 
     { 
      nibName = @"HGSeperatorCell"; 
     } 
     else 
     { 
      nibName = @"HGOtherUserPhotoCell"; 
     } 
    } 

    HGCell *cell = (HGCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (cell == nil) { 

     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; 

     for (id currentObject in topLevelObjects){ 
      if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
       cell = (HGCell *) currentObject; 
       break; 
      } 
     } 
    } 

    //access the cell property here 
    cell.backgroundColor = [UIColor lightGrayColor]; 

    return cell; 
}