我有一个健身计划页面,其中包含一个应用程序,该应用程序是一个具有多个自定义 uitableviewcell 的 UITableViewController。它依赖于相当大的数据馈送——我想在从服务器拉回数据馈送时访问此页面时显示一个加载器。
我已经设置了一个自定义的 uiTableviewCell,其中包含一个样式化的加载器消息/事件指示器,并希望在加载时显示它 - 然后当数据可用时 - 刷新 tableview 并将数据双端队列到相关单元格中。
目前我的 viewdidload 方法中有以下方法,如果提要尚未完成加载,该方法目前会显示警报-
[[RKObjectManager sharedManager].HTTPClient setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
if(status == AFNetworkReachabilityStatusNotReachable)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:nil
message:@"There is no network connection!"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}
else
{
我想改变它以显示加载单元 - 然后在数据加载完成后刷新 View -
我已更改为以下 -
[[RKObjectManager sharedManager].HTTPClient setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
if(status == AFNetworkReachabilityStatusNotReachable)
{
_WoHpTV.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
workoutBannerCell *cell = [_WoHpTV
dequeueReusableCellWithIdentifier:@"loaderCell" ];
}
else
{
所以我在上面得到了对自定义单元格的引用 - 但我的问题是如何将它添加到我的 TableView 中?
最佳答案
i've got a refernce to the custom cell in the above - but my question is how do I add it to my TableView?
您需要实现 UITableView
的数据源方法.因为你想在每个表格单元格中显示加载指示器,你需要一个临时数据(你不能在表格 View 中加载 0 个单元格,即使要显示加载程序你需要一些可见的单元格)。在view did load中创建临时对象数组,调用tableview的reloadData
for(int i = 0; i < 5; i++) {
[_dataArray addObject:@{@"text":@"text_value"}];
_isDataLoaded = NO;
[_table reloadData];
现在这将使用临时数据填充您的表。完成 HTTP 调用后,将 BOOL isDataLoaded
设置为 YES
然后在数据源方法中 -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (!_isDataLoaded)
return _dataArray.count; // No data return count for Temp Data
else
return _feedArray.count; // Return correct feed items count
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"cell_id"];
if (cell == nil)
// Initialise cell here
if (!_isDataLoaded) { // Data has not yet loaded. Set loaders
NSDictionary *data = [_dataArray objectAtIndex:indexPath.row];
// set Cell properties here
} else {
// Fetch data from feed array
}
}
在您的问题中,您正尝试根据 AFNetworkReachabilityStatusNotReachable
检测提要是否已加载。这实际上是不正确的,因为此状态表示没有互联网连接。要跟踪数据的可用性,一个简单的 BOOL 就可以了,如上所示。
关于ios - UITableViewCell - 在拉取数据时显示加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23406810/