ios - 如何暂停调用tableview的reloadData?

标签 ios objective-c uitableview

reloadDataviewDidLayoutSubviews 之后 NSLog 输出,

我希望tableview在GetDataSource之后调用reloadData,第一次加载时没有reloadData。我什至尝试设置 _tableView.dataSource = nil; 并将其设置为 self 在 GetDatasource();

但是 reloadDataGetDatasource(); 之前一直被调用 GetDatasource(); 位于 viewDidload();

  viewWillAppar: <ATOMCutstomNavigationController: 0x1476abfc0>
    viewDidload
     viewWillAppear
    viewWillAppear: <ATOMMyFollowViewController: 0x14751b4c0>
    viewWillLayoutSubviews
    viewDidLayoutSubviews
    reloadData
    viewWillLayoutSubviews
    viewDidLayoutSubviews
    viewDidAppear
    GetDataSource()

有人有任何提示吗? 我该如何暂停reloadData或者我犯了什么错误?

code In viewDidload:
    _myAttentionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAV_HEIGHT - TAB_HEIGHT)];
    self.view = _myAttentionView;
    _tableView = [[RefreshTableView alloc] initWithFrame:_myAttentionView.bounds];
    [_tableView registerClass:[kfcFollowCell class] forCellReuseIdentifier:CellIdentifier];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.estimatedRowHeight = SCREEN_HEIGHT - NAV_HEIGHT - TAB_HEIGHT;
    _tableView.delegate = self;
    _tableView.psDelegate = self;
    _tableView.dataSource = nil;
    [_myAttentionView addSubview:_tableView];
    _tapMyAttentionGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMyAttentionGesture:)];
    [_tableView addGestureRecognizer:_tapMyAttentionGesture];
    _canRefreshFooter = YES;
    _dataSource = [NSMutableArray array];
    [self firstGetDataSource];


- (void)getDataSource {

    Model *sss = [ATOMShowAttention new];
    [sss Get:param withBlock:^(NSMutableArray *resultArray, NSError *error) {
        if (resultArray.count) {
            [_dataSource removeAllObjects];
        }
        for (ATOMCommonImage *commonImage in resultArray) {
            kfcFollowVM * viewModel = [kfcFollowVM new];
            [viewModel setViewModelData:commonImage];
            [_dataSource addObject:viewModel];
        }
        if (!_hasSetSource) {
            _tableView.dataSource = self;
            _hasSetSource = YES;
        }
        [_tableView reloadData];
        [_tableView.header endRefreshing];
    }];
}

最佳答案

在 View 中加载

_myAttentionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAV_HEIGHT - TAB_HEIGHT)];
self.view = _myAttentionView;
_tableView = [[RefreshTableView alloc] initWithFrame:_myAttentionView.bounds];
_dataSource = [NSMutableArray array];//do it HERE..........
[self firstGetDataSource];//do it HERE...........
[_tableView registerClass:[kfcFollowCell class] forCellReuseIdentifier:CellIdentifier];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.estimatedRowHeight = SCREEN_HEIGHT - NAV_HEIGHT - TAB_HEIGHT;
_tableView.delegate = self;
_tableView.psDelegate = self;
_tableView.dataSource = nil;
[_myAttentionView addSubview:_tableView];
_tapMyAttentionGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMyAttentionGesture:)];
[_tableView addGestureRecognizer:_tapMyAttentionGesture];
_canRefreshFooter = YES;

关于ios - 如何暂停调用tableview的reloadData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32086224/

相关文章:

ios - 无效更新 : invalid number of rows in section 0. 更新后现有部分中包含的行数 (3)

ios - Tableview Feed 图像

javascript - iOS HTML 相机预览输入文档

objective-c - NSMigrationManager 'Model already contains an entity named <Entity Name>'

ios - UIPinchGestureRecognizer 像 snapchat 应用程序一样缩放 UIImageView

objective-c - UICollectionViewLayout 教程

ios - 核心数据将相同的对象添加到对多关系

ios - 分组的 UITableView 的背景纹理不会随表格滚动

ruby-on-rails - 自己使用 facebook iOS 客户端授权到服务器

ios - 如何设置 userinteractionEnabled : to NO for an AVPlayerViewController?