如何挂起正在调用的tableview的reloadData?

时间:2015-08-19 03:49:04

标签: ios objective-c uitableview

reloadData之后

NSLog viewDidLayoutSubviews

我希望reloadData之后的tableview调用GetDataSource,首次加载时不需要reloadData。我甚至尝试设置_tableView.dataSource = nil;并在GetDatasource();

中将其设置为self

但在reloadData之前不断调用GetDatasource(); 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];
    }];
}

1 个答案:

答案 0 :(得分:1)

在视图中加载了

_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;