SLComposeViewController

SLComposeViewController

我在Twitter SLComposeViewController上遇到了一个奇怪的问题。我现在在imagePickerController方法中出现错误,提示“将void发送给不兼容类型void(^)(void)的参数”

我还收到警告,其中包含推特图像“从图像选择器中选择的图像”实际上如何从图像选择器中获取图像?谢谢!!

这是照片操作:

-(void) photoAction {
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]
                                                          init];
    #if TARGET_IPHONE_SIMULATOR
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    #else
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    #endif
        imagePickerController.editing = YES;
        imagePickerController.delegate = (id)self;
        [self presentViewController:imagePickerController animated:YES completion:nil];
    }

这是下一个方法:
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [[picker presentingViewController] dismissViewControllerAnimated:YES completion:[self showTweetSheet]];
     }

最后是tweet方法:
-(void)showTweetSheet
{
    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:
                                           SLServiceTypeTwitter];

    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
        switch(result) {
            case SLComposeViewControllerResultCancelled:
                break;
            case SLComposeViewControllerResultDone:
                break;
        }
    };

    [tweetSheet setInitialText:@"Text"];

     if (![tweetSheet addImage:@"image selected from imagepicker"]) {
         NSLog(@"Unable to add the image!");
     }

     if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
         NSLog(@"Unable to add the URL!");
     }

     [self presentViewController:tweetSheet animated:NO completion:^{
        NSLog(@"Tweet sheet has been presented.");
    }];
     }

最佳答案

用单独的方法编写SlcomposeViewController代码

-(void)showTweetSheet
 {
      SLComposeViewController *tweetSheet =
       [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeTwitter];

      tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
          switch(result) {
             case SLComposeViewControllerResultCancelled:
                  break;
             case SLComposeViewControllerResultDone:
                  break;
          }
      };

     [tweetSheet setInitialText:@"Text];

     if (![tweetSheet addImage:image]) {
         NSLog(@"Unable to add the image!");
     }

     if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
         NSLog(@"Unable to add the URL!");
     }

     [self presentViewController:tweetSheet animated:NO completion:^{
         NSLog(@"Tweet sheet has been presented.");
      }];
}

而当关闭imagePickerController时
[[picker presentingViewController] dismissViewControllerAnimated:YES completion:^{
    [self showTweetSheet]
}];

同时在.h文件中声明您的图片实例
UIImage *image;

关于ios - Twitter SLComposeViewController通常无法触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20673474/

10-11 14:38