2

how to switch between multiple views using view controller(with the help of IBAction) ?

This is the code I have written so far:

In the interface file I have made an IBAction:

-(IBAction)Next;

and in the implementation file I have written this:

- (IBAction)Next
{
  SecondPopovercontrol *second = [[SecondPopovercontrol alloc] initWithNibName:nil bundle:nil];
  [self presentingViewController:second animated: YES completion:NULL]; // This is the step I am facing issues with
}

I am unable to get this running- the name of the 2 view controllers are: WOMPopoverController and SecondPopovercontrol.

The error is:

"No visible @interface for WOMPopoverController declares the selector presenting Viewcontroller:animated:completion"

I am new to StackExchange, so if there is any inconsistency in my question please let me know. And, please guide me about how to solve this issue.

thank you

tereško
  • 58,060
  • 25
  • 98
  • 150
KLMM
  • 93
  • 1
  • 13

1 Answers1

5

presentingViewController is a property of a UIViewController. It holds a pointer to the viewController that presented the current viewController (or nil if this viewController was not presented by a presenting viewController).

What you meant to do was send a presentViewController:animated:completion message to self:

[self presentViewController:second animated:YES completion:nil]; 

(that's 'present', not 'presented')

When second is presented, it's presentingViewController property will be set to this self, and self's presentedViewController property will be set to second

edit
as Jef has pointed out, I have mistakenly assumed you are dealing with iOS. On OSX, the approach is similar. An NSViewController has a presentingViewController property, and a presentedViewControllers array. The various presenting methods available to you differ:

– presentViewController:animator:
– presentViewController:asPopoverRelativeToRect:ofView:preferredEdge:behavior:
– presentViewControllerAsModalWindow:
– presentViewControllerAsSheet:

IN any case I think you need to consider the NSViewController documentation carefully to be sure you are using the correct approach for the correct platform (your erroneous method seems to be derived from iOS, not OSX).

edit 2
I have made a small demo app showing the various presentation behaviours for NSViewController on OSX, including a very basic custom animator object.

foundry
  • 31,615
  • 9
  • 90
  • 125
  • @Jef - thanks for pointing that out - i've updated my reply, hopefully I haven't just made things more confusing! – foundry Jan 22 '15 at 01:29
  • @Jef Thanks Jef I meant NSView Controller. – KLMM Jan 22 '15 at 18:48
  • @foundry thanks for the explanation could you give me an example.snippet in which the method: -presentViewController:animator: is used? I have referred to the documentation but couldn't find an example that uses this. – KLMM Jan 22 '15 at 18:48