Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to make a class for method to work with uiviewcontroller
    text
    copied!<p>I am thinking that how can I make a class for twitter or facebook or anything. So just I import that class to my project and it start working with one code. For example. If I use twitter framework then I have to write its functions. I just want to make a class of that funcation which will work on my all future projects by just importing it. example:</p> <p>Any class or anything:</p> <pre><code>-(void)shareOnTwitter:(NSString *)text withUrl:(NSURL *)url withImage:(UIImage *)image { // ALL TWITTER Code HERE; } </code></pre> <p>And in my Main viewController of any project:</p> <pre><code>- (IBAction)socialBtn:(id)sender { [self shareOnTwitter:@"This is Text" withUrl:nil withImage:nil]; } </code></pre> <p><strong>UPDATE: Just tried Category way but no response return, any idea where I am wrong?:</strong></p> <p><strong>UIViewController+CustomMethods.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;Social/Social.h&gt; @interface UIViewController (CustomMethods) -(void)shareOnTwitter:(NSString *)text withUrl:(NSURL *)url withImage:(UIImage *)image; @end </code></pre> <p><strong>UIViewController+CustomMethods.m</strong></p> <pre><code>#import "UIViewController+CustomMethods.h" @implementation UIViewController (CustomMethods) -(void)shareOnTwitter:(NSString *)text withUrl:(NSURL *)url withImage:(UIImage *)image { if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; [tweetSheet setInitialText:text]; [tweetSheet addImage:image]; [tweetSheet addURL:url]; [self presentViewController:tweetSheet animated:YES completion:nil]; } else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't Post a Status right now, make sure your device has an internet connection and you have at least one Twitter account setup" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } @end </code></pre> <p><strong>mainViewController:</strong></p> <pre><code>NSString *title = [webViewOutlet stringByEvaluatingJavaScriptFromString:@"document.title"]; NSURL *url = [[webViewOutlet request] URL]; [self shareOnTwitter:title withUrl:url withImage:nil]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload