ios - 如何将 UIActivityIndi​​catorView 添加到 UITableView 的底部,并在加载时切换它

标签 ios objective-c swift xcode uitableview

我的 UITableView 上有“滚动加载更多”行为。当您滚动到底部时,它开始加载更多内容。我想要实现的是,当服务调用正在进行时,在 UITableView 的底部显示一个 UIActivityIndi​​catorView ,并在添加新项目时隐藏它。

有什么好的方法可以解决这个问题吗?我正在使用 Swift,但也欢迎 Objective-C 解决方案。

Footer loading

最佳答案

我在 Objective-C 中实现了相同的功能

cellForRowAtIndexPath

if (indexPath.row == [self.yourArrayData count] - 1)
{
     // Call the API
     [self loadMoreData:@"all" andPages:[NSString stringWithFormat:@"%ld", (long)pages] AndIsLoadMore:YES];
}

添加加载程序或设计

-(void)addLoaderViewAtBottom {
    viewLoader = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width, 50)];
    [viewLoader setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:viewLoader];

    UIActivityIndicatorView *activityIndicator1 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicator1.center = CGPointMake((SCREEN_SIZE.width/2), 30);
    activityIndicator1.alpha = 1.0;
    activityIndicator1.hidden = NO;
    [viewLoader addSubview:activityIndicator1];

    [activityIndicator1 startAnimating];

}

-(void)hideLoaderView {
[UIView animateWithDuration:1
                 animations:^(void) {
                     [viewLoader setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 50)];

                 }];
}

然后在您的 API 调用方法中使用这两个方法。 API 调用开始时调用 addLoaderViewAtBottom 并在获取响应后调用 hideLoaderView

编码愉快...

关于ios - 如何将 UIActivityIndi​​catorView 添加到 UITableView 的底部,并在加载时切换它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40546702/

相关文章:

jquery - Bootstrap 选项卡 : strange behaviour in ios chrome

iphone - UIButton 和 UIControlEventState 问题

ios - 为什么 NEHotspotHelper registerWithOptions 返回 FALSE?

objective-c - 快速枚举协议(protocol)的有趣任务

iOS Facebook 登录崩溃

swift - iOS 13 自定义字体下载和安装

ios - DispatchGroup 多次返回

ios - 在 CSSearchableItemAttributeSet 中从 NSarray 设置标题属性

ios - 具有类似 scaleAspectFill 行为的 UINavigationBar 背景图像

swift - 如何使用 SwiftUI 呈现小页面?