1

从 UIImagePickerController 选择图像后,我想发推但有错误!

Warning: Attempt to present <SLTwitterComposeViewController: 0x210d84b0> on <UITabBarController: 0x1fd67650> while a presentation is in progress!

PS这是标签栏应用程序(4个标签栏)

所有代码:

    -(void)useCamera:(id)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
        UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
        imagePicker.allowsEditing = NO;
        [self presentViewController:imagePicker animated:YES completion:nil];
        _newMedia = YES;
    }
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSString *mediaType = info[UIImagePickerControllerMediaType];
    [self dismissViewControllerAnimated:YES completion:nil];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        [self buttonTweet:info[UIImagePickerControllerOriginalImage]];
    }
}

- (IBAction)buttonTweet:(id)sender {

    SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    [composeController setInitialText:[NSString stringWithFormat:@"#this is tweet text"]];
    [composeController addImage:sender];
    [composeController addURL: [NSURL URLWithString:@"http://www.abc.com"]];
    [self presentViewController:composeController animated:YES completion:nil];
}
4

1 回答 1

3

您正在展示一个新的视图控制器,而旧的视图控制器仍在消失。您可以像这样在完成另一个动画后呈现新动画:

[self dismissViewControllerAnimated:YES completion:^{
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        [self buttonTweet:info[UIImagePickerControllerOriginalImage]];
    }
}];
于 2013-03-20T19:51:12.310 回答