我在AppDelegate中使用了Web服務。但是我想在初始視圖控制器(視圖控制器)上顯示SVProgressHUD,並且當Web服務完成時,然後在View Controller中隱藏SVProgressHUD。在ViewController上顯示SVProgressHUD?
0
A
回答
0
我理解你的需求,我的建議是套餐二 類,HUD
和Mysevers
:
我這裏有令牌例如:
HUD.m
:
#import "HUD.h"
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
@implementation HUD
+(void)addHUD
{
MBProgressHUD* HUD = [[MBProgressHUD alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)];
HUD.tag = 5000;
HUD.labelText = @"正在加載";
[WINDOW addSubview:HUD];
[HUD show:YES];
}
+(void)removeHUD
{
MBProgressHUD* HUD = (MBProgressHUD*)[WINDOW viewWithTag:5000];
[HUD removeFromSuperview];
HUD = nil;
}
@end
Mysevers.m
:
#import "Mysevers.h"
#import "AFNetworking.h"
#import "HUD.h"
@implementation Mysevers
+(void)AFPOSTAddressname:(NSString*)addressName parmas:(NSDictionary*)parmas RequestSuccess:(void(^)(id result))success failBlcok:(void(^)(void))failBlcok{
[HUD addHUD];
AFHTTPSessionManager *requestManager = [AFHTTPSessionManager manager];
NSString *urlStr = [NSString stringWithFormat:@"%@%@",BASE_URL,addressName];
NSLog(@"%@",urlStr);
/*[requestManager POST:urlStr parameters:parmas success:^(NSURLSessionTask *task, id responseObject) {
[HUD removeHUD];
success(responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"error==%@",[error localizedDescription]);
[HUD removeHUD];
failBlcok();
}];*/
[requestManager POST:urlStr parameters:parmas progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
[HUD removeHUD];
success(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (error != nil) {
NSLog(@"error==%@",[error localizedDescription]);
[HUD removeHUD];
failBlcok();
}
return ;
}];
}
+(void)AFGETAddressname:(NSString*)addressName parmas:(NSDictionary*)parmas RequestSuccess:(void(^)(id result))success failBlcok:(void(^)(void))failBlcok{
[HUD addHUD];
AFHTTPSessionManager *requestManager = [AFHTTPSessionManager manager];
NSString *urlStr = [NSString stringWithFormat:@"%@%@",BASE_URL,addressName];
NSLog(@"%@",urlStr);
/*[requestManager GET:urlStr parameters:parmas success:^(NSURLSessionTask *task, id responseObject) {
[HUD removeHUD];
success(responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"error==%@",[error localizedDescription]);
[HUD removeHUD];
failBlcok();
}];*/
[requestManager GET:urlStr parameters:parmas progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
[HUD removeHUD];
success(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error==%@",[error localizedDescription]);
[HUD removeHUD];
failBlcok();
}];
}
@end
用法
你可以在你的項目的測試:
[Mysevers AFPOSTAddressname:url parmas:params RequestSuccess:^(id result) {
// code here
}
希望這可以幫助你,這是我experience.And,如果你想使用SVProgressHUD
,你也可以更換MBProgressHUD
。
+0
在swift https://github.com/shubh10/JustHUD上試用這個適用於iOS的HUD庫 –
相關問題
- 1. SVProgressHUD如何顯示在下一個ViewController
- 2. SVProgressHUD上顯示內部NSOperationQueue
- 3. SVProgressHUD無法顯示狀態
- 4. svprogresshud沒有顯示在xcode5中ios7
- 5. 活動指示器未顯示SVProgressHUD
- 6. 如何在半屏上顯示ViewController
- 7. 顯示viewController swift
- 8. 在ViewController之外顯示UIAlertController
- 9. 在ContainerView中顯示ViewController
- 10. 顯示ViewController錯誤
- 11. 不再顯示ViewController
- 12. UISplitViewController顯示錯誤的ViewController上推出
- 13. SVProgressHUD顯示在背景爲莫代爾視圖
- 14. 如何設置和解除SVProgressHUD時移動到另一個ViewController
- 15. Dimiss SVProgressHUD
- 16. ViewController沒有顯示... Xcode iPhone
- 17. UIAlertView按鈕來顯示viewController
- 18. LaunchScreen加載後顯示ViewController
- 19. UIModalPresentationStyle.PageSheet不顯示ViewController內容
- 20. 從非UI類顯示ViewController
- 21. 將ViewController顯示爲PopUpSubview?
- 22. UIActivity ViewController顯示項目
- 23. 顯示下一個ViewController塊
- 24. 定時器,而viewController顯示?
- 25. 重置後顯示ViewController NSUSerDefaults
- 26. 顯示另一個ViewController
- 27. 從AppDelegate顯示兩個ViewController
- 28. 如何在第二個ViewController中從一個ViewController顯示UIImage?
- 29. 在模態顯示第二個ViewController後刪除ViewController
- 30. 在另一個ViewController視圖中顯示整個ViewController
可以顯示的appdelegate –
確定沒有問題的代碼,調用[SVProgressHUD秀]前的API調用或解散(使用主線程)獲取響應 –
後 - (無效)GetCountryList { [SVProgressHUD節目]; dispatch_async(dispatch_get_main_queue(),^ { [SVProgressHUD節目]; 的NSString * urlString = [NSString的stringWithFormat:@ 「%@%@」,BASEURL,Service_ListOfCountry]; 的NSDictionary * dicCountry = [WebServiceHelper GetDataFromServer:urlString]; dispatch_async(dispatch_get_main_queue(),^ { [SVProgressHUD節目]; 如果([[dicCountry valueForKey:@ 「msg」 中] isEqualToString:@ 「成功」]){ } [SVProgressHUD駁回]; }); }); } 我用這個,但沒有顯示。 –