ChrisRockC / MyWiki

点-线-面
0 stars 0 forks source link

刷新指定一行数据 #187

Open ChrisRockC opened 7 years ago

ChrisRockC commented 7 years ago
//发通知返回上一页刷新制定某一行数据
            if (type.intValue == 1) {
                NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:self.indexP, @"indexP",self.newsModel,@"newsModel", nil];

                if (self.NewsType == NewsTypeNewest) {
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshNewsWithIndex" object:self userInfo:dict];
                }

                if (self.NewsType == NewsTypeConcern) {
                     [[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshConcernNewsWithIndex" object:self userInfo:dict];
                }
            }
ChrisRockC commented 7 years ago
- (void)addNotificationObserver {
    switch (self.type) {
        case DiscoveryControllerTypeNews: {
            //最新
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callBackAndRefresh:) name:@"RefreshNewsWithIndex" object:nil];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CallBackWithRefresh) name:JKJNotificationName_publishNewsSuccess object:nil];
            break;
        }
        case DiscoveryControllerTypeFollow: {
            //关注
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callBackAndRefresh:) name:@"RefreshConcernNewsWithIndex" object:nil];
            break;
        }

        default:
            break;
    }
}

//动态详情点赞评论完成刷新页面指定的一行
- (void)callBackAndRefresh:(NSNotification *)notice{
    NSIndexPath *indexP = notice.userInfo[@"indexP"];
    JKJNewsDetailModel *detailModel = notice.userInfo[@"newsModel"];
    JKJDiscoveryNewestNewsModel *model = [self.dataList objectAtIndex:indexP.row];
    model.praiseFlag = detailModel.praiseFlag;
    model.commentList = detailModel.commentList;
    model.viewsNum = detailModel.viewsNum;
    model.likeNum = detailModel.likeNum;
    model.newsCount = detailModel.newsCount;
    JKJDiscoveryCell *cell = [self.tableView cellForRowAtIndexPath:indexP];
    [cell configCellWithModel:model indexPath:indexP];
    [self.tableView reloadRowsAtIndexPaths:@[indexP] withRowAnimation:UITableViewRowAnimationAutomatic];
}

- (void)CallBackWithRefresh {
    [self.tableView.mj_header beginRefreshing];
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}