简体   繁体   中英

UIView on the center of UITableViewController

如何将UIView( loadingView )从UITableViewController加载到屏幕中心,无论滚动的位置如何?

You can add the view to the superview of the tableview, like this:

loadingView.center = self.tableView.center;
[self.tableView.superview addSubview:loadingView];

and remove it (removeFromSuperview) when you are done with it. It will appear on top of the table, centered to the table, but won't scroll with the table.

Shift your code into a UIViewController subclass instead of a UITableViewController subclass. That way, you can add your loading view to an actual view instead of a table. Then, conform to UITableViewDelegate and UITableViewDataSource in your .h, set the delegates and add the table as a subview of the main view. You won't even miss that ol' UITableViewController.

Instead of adding the loadingView to the table's subView. Do this instead:

    [[UIApplication sharedApplication].keyWindow addSubview:loadingView];

This solves having to shift code to a UIViewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM