I have a problem when I try to use a shared sharing in social networks but I get an error error: as follows
2015-05-20 14:01:05.267 NovedadesQuintanaRoo[945:174927] Sharing2 2015-05-20 14:01:05.733 NovedadesQuintanaRoo[945:174927] -[UIButton view]: unrecognized selector sent to instance 0x7fb468d8bac0 2015-05-20 14:01:05.741 NovedadesQuintanaRoo[945:174927] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton view]: unrecognized selector sent to instance 0x7fb468d8bac0' *** First throw call stack: ( 0 CoreFoundation 0x0000000110d8ec65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001106cfbb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000110d960ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000110cec13c ___forwarding___ + 988 4 CoreFoundation 0x0000000110cebcd8 _CF_forwarding_prep_0 + 120 5 UIKit 0x000000010fb17de5 -[UIPopoverPresentationController _sourceView] + 39 6 UIKit 0x000000010fb1685f -[UIPopoverPresentationController presentationTransitionWillBegin] + 287 7 UIKit 0x000000010f512d79 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 1305 8 UIKit 0x000000010f5113c0 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 189 9 UIKit 0x000000010f42762c _applyBlockToCFArrayCopiedToStack + 314 10 UIKit 0x000000010f4274a6 _afterCACommitHandler + 533 11 CoreFoundation 0x0000000110cc1ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 12 CoreFoundation 0x0000000110cc1c00 __CFRunLoopDoObservers + 368 13 CoreFoundation 0x0000000110cb7a33 __CFRunLoopRun + 1123 14 CoreFoundation 0x0000000110cb7366 CFRunLoopRunSpecific + 470 15 GraphicsServices 0x0000000112e9ea3e GSEventRunModal + 161 16 UIKit 0x000000010f403900 UIApplicationMain + 1282 17 NovedadesQuintanaRoo 0x000000010d8bf6df main + 111 18 libdyld.dylib 0x00000001119cc145 start + 1 19 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
this is my code if anyone can help me
- (IBAction)compartir:(id)sender{
NSLog(@"Sharing2");
NSString *text = self.story.title;
NSURL *url = self.story.url;
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:self.story.thumb]];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[text, url, image] applicationActivities:nil];
if ([controller respondsToSelector:@selector(popoverPresentationController)]) {
controller.popoverPresentationController.barButtonItem = (UIBarButtonItem *)sender;
}
[self presentViewController:controller animated:YES completion:nil];
}
use the same code on iPhone if I work
this is the code in iPhone:
- (IBAction)share:(id)sender {
NSLog(@"Sharing");
NSString *text = self.story.title;
NSURL *url = self.story.url;
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:self.story.thumb]];
UIActivityViewController *controller =
[[UIActivityViewController alloc]
initWithActivityItems:@[text, url, image]
applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
}
You can't cast sender
to UIBarButtonItem
since sender
is actually a UIButton
.
Change the line:
controller.popoverPresentationController.barButtonItem = (UIBarButtonItem *)sender;
to:
controller.popoverPresentationController.sourceView = sender;