2011-10-04 69 views
1

我打电话给我从MBProgressHUD的rss解析器,目前它在viewdidappear和它的作品,但我希望它在viewdidload,所以当我回去时它不会重新加载它 - 但是,当我将它移动到viewdidload运行进程但不是MBProgressHUD。来自ViewDidLoad的MBProgressHUD调用

- (void)viewDidLoad { 
    [super viewDidLoad]; 

     self.title = @"Results"; 

    HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow]; 


    [self.view.window addSubview:HUD]; 
    HUD.delegate = self; 

    HUD.labelText = @"Loading"; 
    HUD.detailsLabelText = @"updating data"; 

    //Show the HUD while the provided method executes in a new thread 
    [HUD showWhileExecuting:@selector(loadResults) onTarget:self withObject:nil animated:YES]; 


    } 

任何想法?

谢谢,汤姆

回答

0

尝试下面的代码,它在我结束工作的罚款。

- (void)viewDidLoad { 
    [super viewDidLoad];  
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
    HUD.labelText = @"Loading"; 
    HUD.detailsLabelText = @"updating data";  
} 
+0

你在哪里告诉它要加载什么?例如,我使用ShowWhileExecuting位来说我loadResults的子程序运行 – TMB87

+0

我已经添加了你添加了什么,然后我的showWhileExecuting,它现在工作。谢谢 – TMB87

2

在viewDidLoad方法中,将self.view没有它的父窗口和被加载。例如,self.view.superview将被加载到viewWillAppear方法中,然后self.view.window将被加载到viewDidAppear方法中。这就是为什么[self.view.window addSubview:HUD]不会在viewDidLoad中发生,但[self.view addSubview:HUD]的作用。