简体   繁体   中英

How to navigate from one view controller to another view controller?

I have two view controller and in frist view controller i have one button,now i want to that the user wen click that button then they will go to second view controller. I am not using storyboard and do use ARC,I have tried this but it show error "no visible @interface for uiviewcontroller declare the selector alloc".

- (IBAction)SendMsg:(id)sender {

    UIViewController *MessageViewController = [MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
    [self presentModalViewController:MessageViewController animated:YES];
    [MessageViewController release];

}

You are declaring "*MessageViewController" as type UIViewController. And then calling the "MessageViewController" alloc method. You can't do that. Maulik is on the right track, but if you are using ARC you need to remove the last line ([aMessageViewController release];)

try:

- (IBAction)SendMsg:(id)sender{
    MessageViewController *myMessageViewControllerInstance = [[MessageViewController alloc]  initWithNibName:@"MessageViewController" bundle:nil];
    [self presentModalViewController:myMessageViewControllerInstance animated:YES];
}

Don't forget you'll need a way to dismiss the modal view controller, and you can set the presentation and transition styles by adding something like this before the last line above:

myMessageViewControllerInstance.modalPresentationStyle = UIModalPresentationFormSheet;
myMessageViewControllerInstance.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

There are other styles, I just used examples. Good luck

- (IBAction)SendMsg:(id)sender {

    MessageViewController *aMessageViewController = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
    [self presentModalViewController:aMessageViewController animated:YES];
    //[aMessageViewController release]; As you are using ARC

}
    - (IBAction)SendMsg:(id)sender {
        MessageViewController *aMessageViewController = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
        [self presentModalViewController:aMessageViewController animated:YES];
    }
    - (IBAction)SendMsg:(id)sender {

MessageViewController *aMessageViewController = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
[self presentModalViewController:aMessageViewController animated:YES];
[aMessageViewController release];

}

If you used navigation controller than you can used the self.navigationController.......also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM