在菜单视图中对项目进行排序后丢失的项目

Lost item after sorting item in menu view

我在使用 UIActivity 功能时遇到问题。

首先,我创建了 3 activity 个项目:

  1. activityDownload
  2. activityTrash
  3. activityMove.

并添加到 UIActivityViewController 然后,当我呈现 UIActivityViewController 时,其中包括上面的 3 个项目。好的,这里没问题。 然后,当我单击“更多”按钮并对项目进行排序时,例如,我将 "Move" 按钮移到顶部, 点击"Done"按钮后,不知道为什么Download, Trash items丢失了? 移动项目仅显示在 AirDrop 菜单视图中。

NSURL *url = [self fileToURL:self.documentName];
NSArray *objectsToShare = @[url];

AirDropActivityView *activityDownload = [[AirDropActivityView alloc] init];
activityDownload.airDropType = 0;
AirDropActivityView *activityTrash = [[AirDropActivityView alloc] init];
activityTrash.airDropType = 1;
AirDropActivityView *activityMove = [[AirDropActivityView alloc] init];
activityMove.airDropType = 2;

NSArray *uiActivitys = @[activityDownload,activityTrash,activityMove];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:uiActivitys];

// Exclude all activities except AirDrop.
NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook, UIActivityTypePostToWeibo,UIActivityTypeMessage,UIActivityTypePrint, UIActivityTypeCopyToPasteboard UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;

// Present the controller
[self presentViewController:controller animated:YES completion:nil];

https://gist.github.com/tranhieutt/f73999234339f31aa86c

请看截图:

这可能是您正在使用的所有具有相同 activityType 的自定义 UIActivity 视图都会导致此问题。

因此,我建议为您要使用的每个视图创建更多自定义 UIActivity。像这样:

创建AirDropActivityView1; 在AirDropActivityView1.m中,实现:

#import "AirDropActivityView1.h"

@implementation AirDropActivityView

- (NSString *)activityType
{
    return @"youapp.Activity1";
}

- (NSString *)activityTitle
{
    return @"Activity1";
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
    return YES;
}

@end

AirDropActivityView2.m

    #import "AirDropActivityView2.h"

    @implementation AirDropActivityView

    - (NSString *)activityType
    {
        return @"youapp.Activity2";
    }

    - (NSString *)activityTitle
    {
        return @"Activity2";
    }

    - (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
    {
        return YES;
    }

    @end

最后:

    AirDropActivityView1 *activity1 = [[AirDropActivityView1 alloc] init];

    AirDropActivityView2 *activity2 = [[AirDropActivityView2 alloc] init];

    NSArray *uiActivitys = @[activity1,activity2];

现在您可以重新订购它们了。 希望对您有所帮助。