UI活动视图错误

时间:2014-08-24 19:31:14

标签: ios

我是iOS编程的初学者,我搜索了如何实现UI活动视图,但我收到了我不太了解的错误。任何可以帮助我找出错误在更具体细节中意味着什么以及如何解决它们的人都会非常感激。

#pragma mark - SHARING OPTIONS (using a DocumentInteractionController) =============
/* =================
 NOTE: The following methods work only on real device, not iOS Simulator, and you should have apps like Instagram, iPhoto, etc. already installed into your device!
 ================= */
-(void)shareImageToAllAppsAvailable {

    NSLog(@"This code works only on device. Please test it on iPhone!");

    // makes an NSURL file to the processed Image that needs to be saved
    NSURL *fileURL;
    docIntController.delegate = self;

    //Saves the Image to default device directory
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"My Selfie.jpg"];
    UIImage *image = combinedImage;
    NSData *imageData = UIImagePNGRepresentation(image);
    [imageData writeToFile:savedImagePath atomically:NO];

    //Load the Image Path
    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"My Selfie.jpg"];
    // this blank line here creates error 'use of undeclared identifier 'showActivityViewController''

    // Create the URL path to the Image to be saved
    fileURL = [[NSURL alloc] initFileURLWithPath:getImagePath];

    // Open the Document Interaction controller for Sharing options

    -(void)showActivityViewController
    {
        //-- set up the data objects
        NSString *textObject = _aTextView.text;
        UIImage *image = [UIImage imageNamed:@"My Selfie.jpg"];
        NSArray *activityItems = [NSArray arrayWithObjects:textObject, url, image, nil];

        //-- initialising the activity view controller
        UIActivityViewController *avc = [[UIActivityViewController alloc]
                                         initWithActivityItems:activityItems
                                         applicationActivities:nil];

        //-- define the activity view completion handler
        avc.completionHandler = ^(NSString *activityType, BOOL completed){
            NSLog(@"Activity Type selected: %@", activityType);
            if (completed) {
                NSLog(@"Selected activity was performed.");
            } else {
                if (activityType == NULL) {
                    NSLog(@"User dismissed the view controller without making a selection.");
                } else {
                    NSLog(@"Activity was not performed.");
                }
            }
        };

}

1 个答案:

答案 0 :(得分:1)

您在}声明之前错过了结束-(void)showActivityViewController

看起来你试图通过在另一个方法中定义它来调用该方法,该方法不是有效的Objective-C。使用self构造来引用同一类中定义的方法。

#pragma mark - SHARING OPTIONS (using a DocumentInteractionController) =============
/* =================
 NOTE: The following methods work only on real device, not iOS Simulator, and you should have apps like Instagram, iPhoto, etc. already installed into your device!
 ================= */
-(void)shareImageToAllAppsAvailable {

    NSLog(@"This code works only on device. Please test it on iPhone!");

    // makes an NSURL file to the processed Image that needs to be saved
    NSURL *fileURL;
    docIntController.delegate = self;

    //Saves the Image to default device directory
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"My Selfie.jpg"];
    UIImage *image = combinedImage;
    NSData *imageData = UIImagePNGRepresentation(image);
    [imageData writeToFile:savedImagePath atomically:NO];

    //Load the Image Path
    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"My Selfie.jpg"];
    // this blank line here creates error 'use of undeclared identifier 'showActivityViewController''

    // Create the URL path to the Image to be saved
    fileURL = [[NSURL alloc] initFileURLWithPath:getImagePath];

    // Open the Document Interaction controller for Sharing options
    [self showActivityViewController]; //added
} //added

-(void)showActivityViewController
{
    //-- set up the data objects
    NSString *textObject = _aTextView.text;
    UIImage *image = [UIImage imageNamed:@"My Selfie.jpg"];
    NSArray *activityItems = [NSArray arrayWithObjects:textObject, url, image, nil];

    //-- initialising the activity view controller
    UIActivityViewController *avc = [[UIActivityViewController alloc]
                                     initWithActivityItems:activityItems
                                     applicationActivities:nil];

    //-- define the activity view completion handler
    avc.completionHandler = ^(NSString *activityType, BOOL completed){
        NSLog(@"Activity Type selected: %@", activityType);
        if (completed) {
            NSLog(@"Selected activity was performed.");
        } else {
            if (activityType == NULL) {
               NSLog(@"User dismissed the view controller without making a selection.");
            } else {
               NSLog(@"Activity was not performed.");
            }
        }
    };
}