iphone - How to use the Facebook SLComposeViewController in a UIView instead of a UIViewController -


i'm having problem using facebook slcomposeviewcontroller in uiview. problem i'm having because have uiview , not uiviewcontroller i'm inheriting from.

i've imported:

#import <social/social.h> #import <accounts/accounts.h> 

and trying present facebook sharing using:

 slcomposeviewcontroller *controllerslc = [slcomposeviewcontroller composeviewcontrollerforservicetype:slservicetypefacebook]; [controllerslc setinitialtext:@"first post iphone app"]; [controllerslc addurl:[nsurl urlwithstring:@"http://www.test.com"]]; [controllerslc addimage:[uiimage imagenamed:@"test.jpg"]]; [self presentviewcontroller:controllerslc animated:yes completion:nil]; 

it's last line won't present view because i'm inheriting uiview , not uiviewcontroller i'm not sure how fix this. want share image.

thanks help.

uiviews cannot present view controllers. you'll need set way call uiviewcontroller presenting uiview.

a common way make create delegate on view. when happens on view, delegate method called messages view controller implements delegate methods. there, can present view controller parent view controller.

in view's .h file:

@protocol youruiviewdelegate <nsobject> - (void)thedelegatemethod; @end  @interface youruiview : uiview @property (assign, nonatomic) id<youruiviewdelegate> delegate; 

in view's .m file (i'm assuming there's button press or other action method gets called want present view controller):

- (void)buttontapped:(id)sender {     [self.delegate thedelegatemethod]; } 

in view controller .h presenting delegate method:

@interface thepresentingviewcontroller <youruiviewdelegate> 

in view controller's .m file:

- (void)thedelegatemethod {     // of slcomposeviewcontroller code } 

don't forget set view's delegate view controller within presenting view controller.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -