Reputation: 19418
How can I move from the current view to another view? My current view is viewcontroller and I wanted to move another view controller. Here is my code..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SecondView *secondView = [[SecondView alloc] initWithNibName:@"second" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:secondView animated:YES];
}
I am using xib file for another view.
Upvotes: 0
Views: 1338
Reputation: 1824
Be sure about the nib file name and set bundle:nil
okay make sure in interface builder for your second viewcontroller, you correctly hook with the appropriate class.
please clean all targets then build and run the application.
Upvotes: 1
Reputation: 4718
Some notes:
Upvotes: 0
Reputation: 54435
The easiest solution is probably to use a UINavigationController as you're seem to be attempting, as this will let you push views onto the "stack" as required and will also automatically handle the removal of views/adding a navigational back button, etc.
That said, I'd recommend a read of the above class reference as there are some issues with your code. (You're not doing a [secondView release];
after you add the view controller for example.) I presume that "secondView" is also a view controller, not just a view? (You push controllers onto the stack, not views.)
Upvotes: 0
Reputation: 124997
You may be confusing views and view controllers. A view controller manages a view, but it is decidedly not a view, and vice versa. If your "SecondView" is, in fact, a view controller (i.e. it inherits from UIViewController), then your code is correct as far as it goes.
Upvotes: 1