1

I'm trying to create an activity indicator in my app. I'm using a storyboard and I have created a button which is pushing another view.

Here is how I open another view:

- (IBAction)openView {  
    NSLog(@"View is loading");
    @try {
        UINavigationController *nav = [storyboard instantiateViewControllerWithIdentifier:@"viewOpenSegue"];
        [nav setModalPresentationStyle:UIModalPresentationFullScreen];
        [self presentModalViewController:nav animated:YES];
    }
    @catch (NSException *exception) {
        NSLog(@"Error");
    }
    @finally {
        NSLog(@"View loaded");
    }
}  

Everythings good so far. I got the log before view gets opened, and the 2nd log after it is fully loaded.

But when I want to use addSubview method, I am having a weird behavior.

NSArray *subviewArray2 = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];
loadingView = [subviewArray2 objectAtIndex:0];  

That's how I load my view. And I add/remove like this:

[self.view addSubview:loadingView];
//@try block
//@catch block
//@finally
{  
[loadingView removeFromSuperview];  
}  

I expect the view appear and disappear on screen. But it appears for like 1 millisecond right before pushed view appears then disappear suddenly.

If I add this way under viewDidLoad, it appears.

I have seen similar questions but they didn't help me out. Anyone has a clue? Should I try something else?

Thanks in advance.

4

3 に答える 3

0

この nib ファイル View.xib にはファイルの所有者がいますか?

于 2012-04-17T16:48:12.517 に答える
0

これは、最初に viewdidload が viewdidapper メソッドよりも実行されるために発生します。ビューをプッシュまたはポップするたびにviewdidappearがロードされるため、ビューのロードの最初に実行したい場合は、viewdidloadにコードを記述してください。

于 2012-04-17T17:12:13.147 に答える
0

を使っていなかったからselectorです。この質問を参照してください。

最適化されたコードは次のとおりです。

[self.view addSubview:loadingView];  
[self performSelector:@selector(openView) withObject:nil afterDelay:0];
于 2012-04-23T17:49:08.713 に答える