1

我正在尝试使用新的 iOS6 UIActivityViewController,它工作正常,除了 Memory Leaks 仪器说每次我尝试显示控制器时 NSArray *execludedActivities 都会泄漏。

请注意,我尝试使用一个名为 excludeActivities 的 NSArray,然后将 shareShareController.excludedActivityTypes 设置为以后能够将数组设置为 nil (下面的所有注释代码),但现在我直接设置属性并且仍然存在泄漏.

- (IBAction)share:(id)sender
{

    //prepare the image
    UIImage *theImage = [self screenShot];

    //The array of activity Items
    NSArray *activityItems = [[NSArray alloc] initWithObjects:theImage, nil];


   //The acitivyViewController
   UIActivityViewController *shareController = [[UIActivityViewController alloc]   initWithActivityItems:activityItems applicationActivities:nil];

//Excluded Actvivity Types
//NSArray *excludedAcitivities = [[NSArray alloc]   initWithObjects:UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard,UIActivityTypePostToWeibo, UIActivityTypePrint, nil];

shareController.excludedActivityTypes = [[NSArray alloc] initWithObjects:UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard,UIActivityTypePostToWeibo, UIActivityTypePrint, nil];

    //testing fixning the leak of NSArray
    //excludedAcitivities = nil;

    //set the completion handler
    [shareController setCompletionHandler:^(NSString *activityType, BOOL completed) {

        //test hiding the By MunasabaPro lable
        int shareScreen = pageControl.currentPage;
        MainViewController *someController = [viewControllers objectAtIndex:shareScreen];
        someController.byLabel.hidden = YES;
    }];

    [self presentViewController:shareController animated:YES completion:nil];
}

在此处输入图像描述

4

2 回答 2

1

我认为您的完成处理程序中有一个保留周期。看看那个问题

__weak id blockShareController = shareController;
[shareController setCompletionHandler:^(NSString *activityType, BOOL completed) {

       //test hiding the By MunasabaPro lable
        int shareScreen = pageControl.currentPage;
        blockShareController.byLabel.hidden = YES;
    }];
于 2012-11-18T18:05:24.777 回答
0

试试这个,这应该可以解决问题(至少对于我来说):

NSArray *activityItems = [NSArray arrayWithObjects:textToShare, imageToShare, nil];

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

activityVC.excludedActivityTypes = @[
    UIActivityTypePrint,
    UIActivityTypeAssignToContact
];

[self presentViewController:activityVC animated:YES completion:^{
    activityVC.excludedActivityTypes = nil;
    activityVC = nil;
}];
于 2012-11-28T05:42:53.200 回答