我无法让共享按钮在我当前的应用程序中工作,我在我以前的应用程序中成功地拥有一个,但我无法在我的新应用程序中工作。我认为这可能是因为我的第一个应用程序只有一个 ViewController 而这个应用程序有多个。我试图在不同的 View Controller 中执行此操作,而不是默认的主视图 Controller 。不确定我做错了什么。
// 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:.'
非常感谢您的帮助,谢谢!
最佳答案
您需要从 self
而不是 MoreMenuViewController:
[self presentViewController:activityVC
animated:YES
completion:nil];
如果不需要排除类型,也不需要调用此 setter :
activityVC.excludedActivityTypes = @[];
更新:
Despite now being able to click the button the app crashes: -[MoreMenuViewController tellAFriend:]
这是因为你的方法的名称是 tellFriend:
而不是 tellAFriend:
你一定是在没有重构的情况下从代码中重命名了你的方法,所以链接的 IBAction 不知道改变。您需要做的是删除从 Storyboard到您的实现文件的链接。
单击您的按钮,然后单击操作链接到 tellAFriend
的十字:
关于ios - 无法在我的 iOS 应用程序中使用共享按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28634772/