UITableView 标题显示在 MBProgressHUD 顶部
所以我有一个 UITableViewController 的子类,它从互联网加载一些数据并在加载过程中使用 MBProgressHUD。我使用标准 MBProgressHUD 初始化。
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Loading";
[HUD show:YES];
这是结果:
。
有什么办法可以解决这个问题,还是我应该放弃 MBProgressHUD?
谢谢!
So I have a subclass of UITableViewController that loads some data from the internet and uses MBProgressHUD during the loading process. I use the standard MBProgressHUD initialization.
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Loading";
[HUD show:YES];
This is the result:
.
Is there any way to resolve this issue, or should I just abandon MBProgressHUD?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我的解决方案非常简单。我没有使用 self 的视图,而是使用 self 的 navigationController 的视图。
这应该适用于 OP,因为他的图片显示他正在使用
UINavigationController
。如果您没有UINavigationController
,您可以在 UITableView 之上添加另一个视图,并将 HUD 添加到其中。您必须编写一些额外的代码来隐藏/显示这个额外的视图。这个简单的解决方案的不幸之处在于(不包括我添加上面提到的另一个视图的想法)意味着用户在显示 HUD 时无法使用导航控件。对于我的应用程序来说,这不是问题。但如果您有一个长时间运行的操作并且用户可能想按“取消”,这将不是一个好的解决方案。
My solution was pretty simple. Instead of using self's view, I used self's navigationController's view.
This should work for the OP because his picture shows he's using a
UINavigationController
. If you don't have aUINavigationController
, you might add another view on top of your UITableView, and add the HUD to that. You'll have to write a little extra code to hide/show this extra view.An unfortunate thing with this simple solution (not counting my idea adding another view mentioned above) means the user can't use the navigation controls while the HUD is showing. For my app, it's not a problem. But if you have a long running operation and the user might want to press Cancel, this will not be a good solution.
这可能是因为 self.view 是一个 UITableView,它可以动态添加/删除包括标题在内的子视图,在将其添加为子视图后,这些子视图可能最终出现在 HUD 的顶部。您应该将 HUD 直接添加到窗口,或者(为了多做一点工作,但可能会得到更好的结果)您可以实现一个 UIViewController 子类,它有一个包含表视图和 HUD 视图的普通视图。这样你就可以将 HUD 完全放在表格视图的顶部。
It's probably because
self.view
is a UITableView, which may dynamically add/remove subviews including the headers, which could end up on top of the HUD after you add it as a subview. You should either add the HUD directly to the window, or (for a little more work but perhaps a better result) you could implement a UIViewController subclass which has a plain view containing both the table view and the HUD view. That way you could put the HUD completely on top of the table view.我的解决方案是:
对于涉及 UITableViewController 的所有场景都像魅力一样工作。我希望这对其他人有帮助。快乐编程:)
My solution was:
Works like a charm for all scenarios involving the UITableViewController. I hope this helps someone else. Happy Programming :)
在 UITableView 上创建一个类别,它将采用您的 MBProgressHUD 并将其带到前面,通过这样做,它将始终显示在“顶部”,并让用户在您的应用程序中使用其他控件,例如后退按钮,如果操作花费很长时间(例如)
Create a category on UITableView that will take your MBProgressHUD and bring it to the front, by doing so it will always appear "on top" and let the user use other controls in your app like a back button if the action is taking to long (for example)
一个简单的修复方法是为 HUD 视图的 z-index 赋予一个较大的值,确保其放置在所有其他子视图的前面。
查看此答案以获取有关如何编辑 UIView 的 z-index 的信息: https://stackoverflow.com/a/4631895/1766720< /a>.
A simple fix would be to give the z-index of the HUD view a large value, ensuring it is placed in front of all the other subviews.
Check out this answer for information on how to edit a UIView's z-index: https://stackoverflow.com/a/4631895/1766720.
几分钟前,我遇到了类似的问题,并在以不同的(恕我直言更优雅)方式指向正确的方向后能够解决它:
添加以下行 < 开始
UITableViewController
子类实现:添加以下代码到
init的开头
方法UITableViewController
子类,如initWithNibName:bundle:
(viewDidLoad
的开头也可能有效,尽管我建议使用init
方法):那么您不需要再更改您在问题中发布的代码。上面的代码所做的基本上是将
self.tableView
与self.view
分开(这是对与self.tableView
相同对象的引用)之前,但现在是一个包含表格视图的 UIView,正如人们所期望的那样)。I've stepped into a similar problem a few minutes ago and was able to solve it after being pointed to the right direction in a different (and IMHO more elegant) way:
Add the following line at the beginning of your
UITableViewController
subclass implementation:Add the following code to the beginning of your
init
method of yourUITableViewController
subclass, likeinitWithNibName:bundle:
(the beginning ofviewDidLoad
might work as well, although I recommend aninit
method):Then you don't need to change your code you posted in your question any more. What the above code does is basically seperating the
self.tableView
fromself.view
(which was a reference to the same object asself.tableView
before, but now is aUIView
containing the table view as one might expect).我刚刚手动解决了这个问题,克里斯·巴林格 (Chris Ballinger) 提问已经过去两年了,但也许有人已经习惯了这里发生的事情。
在 UITableViewController 中,我在 viewDidLoad 中执行一个 HTTP 方法,该方法在后台运行,因此在显示进度时加载表视图,从而导致错过。
我添加了一个 false 标志,在 viewDidLoad 中将其更改为 yes,在 viewDidAppear 中类似的东西可以解决该问题。
I've Just solved that issue manually , it has been 2 years since Chris Ballinger asked but maybe someone get used of what is going on here.
In UITableViewController i execute an HTTP method in viewDidLoad , which is running in background so the table view is loaded while the progress is shown causing that miss.
i added a false flag which is changed to yes in viewDidLoad, And in viewDidAppear something like that can solve that problem.
我遇到了同样的问题,并决定通过将 UITableViewController 更改为普通 UIViewController 来解决此问题,该 UITableView 作为子视图(类似于 jtbandes 在他接受的答案中提出的替代方法)。此解决方案的优点是导航控制器的 UI 不会被阻塞,即用户可以简单地离开 ViewController,以防他们不想再等待您及时的操作完成。
您需要进行以下更改:
头文件:
实现文件:
方法
-(CGRect)boundsFittingAvailableScreenSpace
是我的UIViewController 的一部分+FittingBounds 类别
。您可以在这里找到它的实现:https://gist.github.com/Tafkadasoh/5206130。I had the same problem and decided to solve this by changing my UITableViewController to a plain UIViewController that has a UITableView as a subview (similar to what jtbandes proposed as an alternative approach in his accepted answer). The advantage of this solution is that the UI of the navigation controller isn't blocked, i.e. users can simply leave the ViewController in case they don't want to waiting any longer for your timely operation to finish.
You need to do the following changes:
Header file:
Implementation file:
The method
-(CGRect)boundsFittingAvailableScreenSpace
is part of myUIViewController+FittingBounds category
. You can find its implementation here: https://gist.github.com/Tafkadasoh/5206130.以 .h 表示
以 .m 表示
In .h
In .m
这应该有效。
要删除你可以尝试
This should work.
And to remove you can try