问题描述:

I am having a problem to display a View. When a button is pressed in current view, following action is exected:

- (IBAction) vistaUser: (id)sender{

loginTabController *theInstance = [[loginTabController alloc] init];

[theInstance logIn:user.text :password.text];

}

then, following logIn function is called who have to show userViewControler view but it is not showed. View remains at current one. However, userViewController view is initialized and getData function from this view executed! I do not understand why called view is not displayed! Thanks for help!

- (void)logIn: (NSString *)strUser: (NSString *)strPass

{

[UIView beginAnimations:@"View Flip" context:nil];

[UIView setAnimationDuration:1.0];

[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];

if (self.controladorUser == nil)

{

userViewController *aController = [[userViewController alloc] initWithNibName:@"userViewController" bundle:nil];

self.controladorUser = aController;

[aController release];

}

[UIView setAnimationTransition: UIViewAnimationOptionCurveEaseIn forView:self.view cache:YES];

[self.controladorPass viewWillDisappear:YES];

[self.controladorUser viewWillAppear:YES];

[self.controladorPass.view removeFromSuperview];

[self.view insertSubview:controladorUser.view atIndex:0];

[self.controladorPass viewDidDisappear:YES];

[self.controladorUser viewDidAppear:YES];

[UIView commitAnimations];

//getData call

userViewController *theInstance = [[userViewController alloc] init];

[theInstance getData:strUser :strPass];

}

网友答案:

You are never showing your loginTabController's view. Therefore when you add the UserViewController's view to the tabViewController's view it doesn't do anything. Try this:

- (IBAction) vistaUser: (id)sender{

    loginTabController *theInstance = [[loginTabController alloc] init];
    [self.view addSubview:theInstance.view];
    [theInstance logIn:user.text :password.text];

}

That should get it working, but there are some general code design issues that you may want to address:

  1. Use the newer block animation functions in UIView instead of the older and more difficult "beginAnimations" "commitAnimations" methods.
  2. It does not make sense to call a viewController that immediately calls another viewController. Skip the loginTabController and just go straight to the userViewController. If for some reason you want to keep the code the loginTabController is using as a separate class that's fine just don't use a viewController subclass for it.
相关阅读:
Top