Maulik
Maulik

Reputation: 19418

Move to another view on UITableView row selection

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

Answers (4)

makboney
makboney

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

ZaBlanc
ZaBlanc

Reputation: 4718

Some notes:

  • You're leaking secondView, autorelease it
  • bundle can probably be nil
  • What's wrong with the code?

Upvotes: 0

John Parker
John Parker

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

Caleb
Caleb

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

Related Questions