开发者

Best way to disable UIViewController interaction and show activity indicator while loading data from web service or core data?

开发者 https://www.devze.com 2023-04-06 07:43 出处:网络
Question says it all. Is there a best recipe to follow to disable user interaction and show a activity indicator while fetching data from a web service or loading data from a core data fetch operati

Question says it all.

Is there a best recipe to follow to disable user interaction and show a activity indicator while fetching data from a web service or loading data from a core data fetch operation?

I'm using A开发者_运维技巧SIHTTPRequest, JSONKit and Core Data in my particular app so any sample code using those Apis would be preferred.

Thanks - wg


Create a UIView with transparent background and that takes the whole screen.

It will intercept the interaction and won't let the user tap on the other items on the screen.

Then you can add an UIActivityIndicator (and even a UILabel) as a subview of this transparent fullscreen view or whatever you need.

Note that there are multiple existing projects like SVProgressHUD that do that already too and that I strongly recommand.


A very very simple and easy way to accomplish both tasks is using MBProgressHUD.

Check it's repository in Github

Example usage:

+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;

+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated;

These two class methods will show/hide a simple activity indicator with a translucid background. It also has properties to show text, progress and a good delegate.


Use the up mentioned HUD control on rootViewContoller. It will not let user to interact with UI.

0

精彩评论

暂无评论...
验证码 换一张
取 消