yoeriboven
yoeriboven

Reputation: 3571

'presentedViewController' while having multiple views

I'm learning Objective-C but I'm stuck at this point where it comes to multiple view controllers. I learned that if you have multiple views on your storyboard, you have to make a separate file (e.g. ViewTwoControllor.h and .m) and link these files to your views by clicking on them and in the panel on the right on the third tab you have to type in 'ViewTwoController'. I get it to e.g. open a website in Safari by clicking on an button. But I want Twitter integration in the second view.

Twitter iOS 5 integration goes fine until I put it on the second view. I use the following code for the button.

TWTweetComposeViewController *tweet = [[TWTweetComposeViewController alloc]init];

[tweet setInitialText:@"This is a pretty awesome application bro."];
[tweet addURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.stackoverflow.com"]]];

[self presentedViewController:tweet animated:YES completion:nil];

Twitter framework is included and IBAction etcetera is fine either. This works in a single-view app but now I get the following error: "Receiver type 'ViewTwoController' for instance message does not declare a method with selector 'presentedViewController:animate:completion:'.

Someone in the room who knows how to fix this?

Upvotes: 0

Views: 2032

Answers (1)

Evan Cordell
Evan Cordell

Reputation: 4118

You probably want presentModalViewController, not presentedViewController

Take a look a the documentation for UIViewController. You see that you have two options in this case: presentViewController:animated:completion and presentModalViewController:animated

If you're new to Objective-c, a selector is essentially just a method name. The error message is telling you what the problem is: you're trying to send a message (the selector, in this case presentedViewController:animated:completion) to an object that doesn't know how to respond to that message (in this case, an instance of ViewTwoController). This suggests that either the method you're calling is incorrect, or the object you're trying to call the method on isn't a subclass of what you think.

Upvotes: 1

Related Questions