Objective c 从HUD到Singleton
我想设置在Singleton中显示和取消HUD的方法。我用singleton编写此方法:Objective c 从HUD到Singleton,objective-c,singleton,mbprogresshud,Objective C,Singleton,Mbprogresshud,我想设置在Singleton中显示和取消HUD的方法。我用singleton编写此方法: - (void)showHUD { activityHud = [[MBProgressHUD alloc] init]; activityHud.delegate = self; } 但什么也没发生。对于解雇,我不知道如何写。。。任何答案都会很有帮助。谢谢 为什么不使用静态方法?我使用它并将其放在我的util类中 static UIWindow *window; + (MBProgr
- (void)showHUD
{
activityHud = [[MBProgressHUD alloc] init];
activityHud.delegate = self;
}
但什么也没发生。对于解雇,我不知道如何写。。。任何答案都会很有帮助。谢谢 为什么不使用静态方法?我使用它并将其放在我的util类中
static UIWindow *window;
+ (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString *)title {
window = [[[UIApplication sharedApplication] windows] lastObject];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
hud.labelText = title;
return hud;
}
用这个来隐藏它:
+ (void)dismissGlobalHUD {
[MBProgressHUD hideHUDForView:window animated:YES];
}
你可以做我做的事。我有一个基本VC类,我的所有viewControllers子类都来自该类,并有以下方法:
-(void)showActivityViewForView:(UIView *)view withActivityText:(NSString *)text;
及
实施如下:
-(void)showActivityViewForView:(UIView *)view withActivityText:(NSString *)text;
{
self.viewForActivity = view;
self.activitytext = text;
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showActivityView) userInfo:nil repeats:NO];
}
-(void)showActivityView
{
self.progressView = [MBProgressHUD showHUDAddedTo:self.viewForActivity animated:YES];
self.progressView.opacity = 0.5;
self.progressView.labelText = self.activitytext;
}
-(void)hideActivityView
{
[self.timer invalidate];
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}
计时器在那里,因此如果我完成的网络活动不到一秒钟,我根本不显示MBProgressHUD
将它放在基类中意味着我所有的VC都可以轻松访问这些方法 这看起来一点也不像单例模式。因为这是单例模式中唯一的方法,所以在这里不需要使用此方法复制/粘贴整个单例模式……您正在实例化一个对象并设置其委托属性。显示它的代码在哪里?
-(void)showActivityViewForView:(UIView *)view withActivityText:(NSString *)text;
{
self.viewForActivity = view;
self.activitytext = text;
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showActivityView) userInfo:nil repeats:NO];
}
-(void)showActivityView
{
self.progressView = [MBProgressHUD showHUDAddedTo:self.viewForActivity animated:YES];
self.progressView.opacity = 0.5;
self.progressView.labelText = self.activitytext;
}
-(void)hideActivityView
{
[self.timer invalidate];
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}