首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS应用故障

iOS应用故障
EN

Stack Overflow用户
提问于 2016-08-29 09:13:40
回答 2查看 89关注 0票数 0

我正在调试一个应用程序,有一个小故障。我在应用程序和互联网上查了一下,但什么也没找到。

你可以从下面找到故障

看上去就像下面那个很短的时间间隔。

我的代码:

代码语言:javascript
复制
- (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;
            }
        }
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-01 12:40:20

reloadData有一个问题。旧代码如下所示

代码语言:javascript
复制
[weakSelf.collectionView reloadData];

我把它改成了这个

代码语言:javascript
复制
[weakSelf.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];

它解决了我的问题。文字中不再有小故障,而是图片上的一个小故障。但是它看起来很酷,所以我要保存它:)

票数 0
EN

Stack Overflow用户

发布于 2016-09-01 07:52:34

如果您根据条件显示了许多自定义单元格,那么您必须正确地重用tableview cells.create --一个常见的UITableViewCell类(在您的示例中是例如: HGCell) --您可以根据您的需要创建多个nib(例如: HGOtherUserTopInformationCell、HGSeperatorCell.)。下面的代码显示了处理许多单元格的示例。

代码语言:javascript
复制
 - (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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39202498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档