문제

I have a NavigationController and one of the tabs is supposed to load a ViewController.

This ViewController (1), when loaded on "viewDidLoad" does some stuff and then pushes a new ViewController (2). The thing is that after ViewController (1) has already passed through viewDidLoad, it won't pass through it again, unless the app is restarted.

Could you guys please refer a clever way to to this?

Here's what I am really doing:

- (void)viewDidLoad
{
    // Keep track of cash using NSUserDefaults
    BOOL dreceived[63];
    int rightData;

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //Load cash switches
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSData *data = [prefs objectForKey:@"dreceived"];
    memcpy(&dreceived, data.bytes, data.length);

    for(int n = 72; n >= 1; n = n - 1)
    {
        if(dreceived[n-1]==1)
        {
            rightData = n;            

        }
    }
    NSLog(@"Right Data %d", rightData);

    CashItem *c = [cashflow objectAtIndex:rightData];

    // Go for details
    CashDetailedViewController *cdetail = [[[CashDetailedViewController alloc] init] autorelease];
    cdetail.cash = c;

    cdetail.navigationItem.hidesBackButton = YES;
    [self.navigationController pushViewController:cdetail animated:YES];

}

The thing is, this code is never called again. And if I touch the tab twice, a blank view is displayed (th original xib view).

Thanks!

도움이 되었습니까?

해결책

It sounds like you would want to use viewWillAppear. It is called every time that your view controller is about to be onscreen.

Although, based on what you've posted, you may want to rethink what your doing. Having a view controller that immediately presents another view controller should like it would lead to a confusing user experience.

다른 팁

Put your code in - (void)viewWillAppear instead

Try calling

[yourViewController.view setNeedsDisplay];

Or you could spin the code out to a seperate method and call it in viewDidLoad and viewDidAppear:animated

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top