문제

... I guess. This is the situation:

here a simple method, in a view controller, where we can push a botton to go in another view:

- (IBAction)actionNext:(UIButton *)sender {

    self.numeriUtiliListaViewController = [[ALCNumeriUtiliListaViewController alloc] init];
    [self.numeriUtiliListaViewController.view setTag:[sender tag]];
    [self.delegate vai:self.numeriUtiliListaViewController title:@"Numeri Utili"];
    }

the delegate's method is:

- (void)vai:(id)view title:(NSString *)title
{
    ALCParentViewController *viewController = (ALCParentViewController *)view;  
    viewController.delegate = self;
    NSLog(@"tag: %d",[viewController.view tag]);

    [self.myNavigationController pushViewController:viewController animated:YES];
}

This system works well, but the only thing is the tag that i've logged in this last method, here it was print correctly, but in the view loaded by the navigation controller, when i try to catch the value in the viewDidLoad, it's 0.

Any ideas?

Thanks in advance

Update 1 2013-01-30:

if i try to print the the tag in the viewWilAppear method of the viewcontroller pushed in the navigationcontroller, i'll give the right value... why? i don't know

도움이 되었습니까?

해결책

Whats happening here is that in your actionNext method, when you are setting the tag of the viewController's view using : self.numeriUtiliListaViewController.view, as soon as you access the view propert of the viewController, viewDidLoad method is called in the viewController. So even before the setTag function is executed, viewDidLoad has already been executed, and it is showing tag = 0. But your viewWillAppear/viewDidAppear methods will be called only when the actual view appears and by then setTag has been executed, so it shows correct value. Makes sense? Hope this helps

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