我无法在我当前的应用程序中使用“共享”按钮,我在之前的应用程序中成功使用了一个,但我无法在我的新应用程序中使用它。我想这可能是因为我的第一个应用程序只有一个ViewController,而这个应用程序有多个。我试图在不同的视图控制器中执行此操作,而不是默认的主视图。不知道我做错了什么。
// MoreMenuViewController.h
#import <UIKit/UIKit.h>
@interface MoreMenuViewController : UIViewController
- (IBAction)tellFriend:(id)sender;
// MoreMenuViewController.m
#import "MoreMenuViewController.h"
@implementation MoreMenuViewController
- (IBAction)tellFriend:(id)sender
{
NSString *shareText = [NSString stringWithFormat:@"Check out Stories With Friends, a new word game for iPhone!"]; // Share message
NSArray *itemsToShare = @[shareText];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[];
[MoreMenuViewController:activityVC animated:YES completion:nil];
}
对于最后一行代码我得到一个错误:选择器'animated:completion:。'没有已知的类方法。
帮助会更加明确,谢谢!
答案 0 :(得分:3)
您需要从self
而不是MoreMenuViewController:
[self presentViewController:activityVC
animated:YES
completion:nil];
如果您不需要排除类型,也不需要致电此setter:
activityVC.excludedActivityTypes = @[];
更新:
尽管现在能够点击按钮,但应用程序崩溃了: - [MoreMenuViewController tellAFriend:]
这是因为您的方法名称为tellFriend:
而非tellAFriend:
您必须从代码重命名您的方法而不进行重构,因此链接的IBAction不知道更改的线索。您需要做的是将您的Storyboard中的链接删除到您的实现文件。
点击您的按钮,然后点击操作链接到tellAFriend
的十字架:
答案 1 :(得分:0)
尝试[self presentViewController:activityVC animated:YES completion:nil];
代替