UIActivity ViewController显示项目

时间:2015-03-30 23:58:03

标签: ios objective-c uiactivityviewcontroller

所以我已将我的Activity控制器链接到共享按钮正常工作。每当我指向特定项目时,它都会填充文本和图像,但我使用的是文本和图像数组,我希望它在用户滑动到下一页时自动填充数组中的项目。但它似乎没有正确呈现自己。以下是我的代码:

{
    NSString *shareApp2 = @"Test Share Button";
    UIImage *shareImage2 = [UIImage imageNamed:@"challenge@2x.png"];
    NSString *shareChallenge = @"Challenge";
    NSArray *shareDays2 = self.pageDays2;
    NSArray *shareText2 = self.pageTitles2;
    NSArray *itemsToShare2 = @[shareApp2, shareImage2, shareChallenge, shareDays2, shareText2,];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare2 applicationActivities:nil];
    activityVC.excludedActivityTypes = @[UIActivityTypeAirDrop, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypeAssignToContact];
    [self presentViewController:activityVC animated:YES completion:nil];
}

问题出在以下两个方面:

NSArray *shareDays2 = self.pageDays2;
NSArray *shareText2 = self.pageTitles2;

如果我这样呈现它会工作正常,但它只会填充数组上的特定项目,我将其指向为整数:

NSArray *shareDays2 = self.pageDays2 [0];
NSArray *shareText2 = self.pageTitles2 [0];

我尝试过多次ARC和Count或自我呈现的方法而且没有运气,我知道它看起来非常简单。如果您需要源文件或更多详细信息,请告诉我,谢谢

1 个答案:

答案 0 :(得分:0)

试用此代码进行分享:

NSString *textToShare = @"Look at this awesome website for aspiring iOS Developers!";

NSURL *myWebsite = [NSURL URLWithString:@"http://www.codingexplorer.com/"];

NSArray *objectsToShare = @[textToShare, myWebsite];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];

NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                               UIActivityTypePrint,
                               UIActivityTypeAssignToContact,
                               UIActivityTypeSaveToCameraRoll,
                               UIActivityTypeAddToReadingList,
                               UIActivityTypePostToFlickr,
                               UIActivityTypePostToVimeo];

activityVC.excludedActivityTypes = excludeActivities;

[self presentViewController:activityVC animated:YES completion:nil];

参考: http://www.codingexplorer.com/add-sharing-to-your-app-via-uiactivityviewcontroller/