Reputation: 163
I have a split-view app with a button in the detail view that, when clicked, will take the user to a full screen view of the selected image.
I understand that I need a new nib file and view controllers, but I'm not sure how to connect these new files with my existing RootViewController and DetailViewController files.
I know this is really vague, but any help at all would be most appreciated.
Upvotes: 3
Views: 18204
Reputation: 3268
As long as you are moving to a single view(as in not another split view) you should only need one more view controller. If I understand what you are doing, then the progression should be something along the lines of:
Declare the specific instance of your new view controller, in this case called newViewController, in DetailViewController.h and synthesize it in DetailViewController.m
@interface DetailedViewController
{
NewViewController *newViewController;
}
@property (nonatomic, retain) NewViewController *newViewController;
@end
Add your IBAction to the header file of DetailViewController, this will be the function responsible for actually triggering your view switching
Implement the view switch action in your DetailViewController.m file, should look something like this:
(IBAction)switchToNewView:(id)sender
{
if (newViewController == nil)
{
NewViewController *newViewController =
[[NewViewController alloc]
initWithNibName:@"NewViewController"
bundle:[NSBundle mainBundle]];
self.newViewController = newViewController;
}
// How you reference your navigation controller will
// probably be a little different
[self.navigationController
pushViewController:self.newViewController
animated:YES];
}
Then in your DetailViewController.m file inside of the viewDidLoad function add the following:
UIBarButtonItem *addButton =
[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButtonSystemItemAdd
target:self action:@selector(switchToNewView:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
The other option that you have if you choose to implement this through a UIButton, is to go create the button in Interface Builder on your NewViewController.xib, then select it, and in the Connections inspector, create a link between the "touchUpInside" event and the file owner, and then select your switchToNewView IBAction. This should accomplish the same thing.
Thats the general idea. I hope that helps!
EDIT: As asked in the comments, if adding a button as a UIBarButton as part of a navigation controller you would simply need to do something like below:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(switchToNewView:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
Upvotes: 6