gpt4 book ai didi

ios - 将事件指示器 View 居中到 UITableView

转载 作者:可可西里 更新时间:2023-11-01 05:35:43 25 4
gpt4 key购买 nike

我在 Storyboard 中创建了一个 UITableViewController,然后将一个 Activity Indicator View 拖到 Controller 中(同时为它创建了一个 outlet),我在一些 json 内容之前和之后开始和停止动画已加载。

我可以看到 ajax 微调器工作正常,但它在视觉上显示在我的导航器/标题区域下方,当我尝试将它居中时,它看起来居中宽度方向,出现在状态区域附近的最顶部......

我尝试了以下尝试使其居中...快速浏览一下我的 viewDidLoad:

- (void)viewDidLoad
{
[super viewDidLoad];

self.listLoader.center = CGPointMake( [UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
UITableView *appDelegate = (UITableView *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview:self.listLoader];

self.operationQueue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getPosts) object:nil];
[self.operationQueue addOperation:operation];
}

请注意,我的 startAnimatingstopAnimating 都包含在我的 getPosts 方法中,并在主线程上执行。所以,为了避免混淆,我实际上可以看到微调器,它一直到状态区域。事实上,如果我删除这些行...

self.listLoader.center = CGPointMake( [UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
UITableView *appDelegate = (UITableView *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview:self.listLoader];

微调器出现在导航栏的正下方...

我究竟该如何居中呢???我认为上面的方法会起作用,但显然它不起作用....

最佳答案

您遇到的问题是 UITableViewController 处理单个 tableView,tableView 是一种特殊的 ScrollView ,会根据内容而变化。向 tableviews 添加东西是非常不常见的,这就是为什么你使用原型(prototype)单元格并更改这些单元格。没有“unhacky”的方法来做到这一点。

做到这一点的正确方法是,有一个带有 TableView 的普通 ViewController 和一个带有指示器的 View 。然后使 View Controller 符合处理 TableView 的数据源和委托(delegate)协议(protocol)。

如果你仍然想使用 tableviewcontroller,这是一个不太老套的方法:

UITableView Activity Indicator the Apple way

关于ios - 将事件指示器 View 居中到 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20695621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com