3

我有一个 NavigationController,其中一个选项卡应该加载一个 ViewController。

这个 ViewController (1) 在加载到“viewDidLoad”时会做一些事情,然后推送一个新的 ViewController (2)。问题是 ViewController(1) 已经通过 viewDidLoad 之后,它不会再通过它,除非重新启动应用程序。

各位大神能不能给个聪明的办法?

这就是我真正在做的事情:

- (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];

}

问题是,这段代码再也不会被调用。如果我两次触摸选项卡,则会显示一个空白视图(原始 xib 视图)。

谢谢!

4

3 回答 3

7

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.

于 2013-03-22T15:15:54.210 回答
0

把你的代码- (void)viewWillAppear放进去

于 2013-03-22T15:12:46.623 回答
-1

试着打电话

[yourViewController.view setNeedsDisplay];

或者您可以将代码旋转到一个单独的方法并在 viewDidLoad 和 viewDidAppear:animated 中调用它

于 2013-03-22T15:11:31.980 回答