vivek241
vivek241

Reputation: 664

How do i transition between views, each having their own view controller?

I created a single view application on X-Code and created another view controller and tried pushing the second view controller.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath     *)indexPath
{   
if (self.statesView == nil)
{
    StatesView *newStateView = [[StatesView alloc]initWithNibName:@"StatesView" bundle:[NSBundle mainBundle]];
    self.statesView = newStateView;
}

[self.navigationController pushViewController:self.statesView animated:YES];
}

But the application crashes with SIGABRT signal

Upvotes: 0

Views: 112

Answers (3)

Oyashiro
Oyashiro

Reputation: 505

Is StatesView a ViewController ? pushViewController: needs a UIViewController, not a UIView.

I think you are trying to change ViewController when you are tapping a row in a UITableView. The easier and best way to achieve this is to use segues. In your storyboard, ctrl drag your UITableViewCell and link it with your new view controller.

If you want to do it programmatically, you need to use :

[self.storyboard instantiateViewControllerWithIdentifier:@"StatesViewController"];

Upvotes: 1

touti
touti

Reputation: 1164

you can animate the transition between views like this

CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionPush; //choose your animation
[viewController.view.layer addAnimation:transition forKey:nil];
[self.viewController1.view addSubview:viewController2.view];
dont forget to import the QuartzCore lib !!

Upvotes: 0

adig
adig

Reputation: 4057

So, your StatesView instance (i.e. newStateView) is a UIView subclass, so it's a view, not a controller. You can only use pushViewController when you send an UIViewController subclass to it. You can add your the newStateView to the current view using :

[self.view addSubview:self.statesView];

But that does it without any transition. You can animate view properties using [UIView animateWithDuration:animations:]

Upvotes: 0

Related Questions