关闭模态视图控制器时出现问题

3

当我关闭模态视图时,遇到了问题:

我有一个带有五个标签的选项卡。 我在第四个选项卡上,并显示一个模态视图。 当我关闭它时,我会回到第一个选项卡,但我想留在第四个选项卡。

为了显示模态视图,我在父控制器中调用了这个方法:

[self presentModalViewController:controller animated:YES];

为了隐藏模态框,我在父控制器中调用此方法:
[self dismissModalViewControllerAnimated:YES];

我已经尝试调用self.tabBarController/self.navigationController方法而不是self方法,但问题仍然存在。有人有想法吗?
编辑:
我在第四个标签的控制器中调用这些方法。
这是上下文:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
    imgPicker.allowsEditing = NO;
    imgPicker.delegate = self;
    switch (buttonIndex) {
        case 0: {
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kMobiglissFromPicker];
            imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentModalViewController:imgPicker animated:YES];
            break;
        }
        case 1: {
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kMobiglissFromPicker];
                imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
                [self presentModalViewController:imgPicker animated:YES];
            }               
            break;
        }
    }
}

- (void)imagePickerController:(UIImagePickerController *)imgPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *origin = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    UIImage *photo = [origin thumbnailImage:280
                          transparentBorder:0.0
                               cornerRadius:0.0
                       interpolationQuality:kCGInterpolationHigh];

    [icon replaceImageWithImage:photo];

    [serverProxy updateProfileAvatar:photo];
    [self dismissModalViewControllerAnimated:YES];
    imgPicker.delegate = nil;
}

- (IBAction)editAvatar:(id)sender {
    NSString *camera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ? [WPLanguage get:@"SignupPhotosheetCamera"] : nil;
    UIActionSheet *photoSheet = [[UIActionSheet alloc] initWithTitle:[WPLanguage get:@"SignupPhotosheetTitle"]
                                                            delegate:self 
                                                   cancelButtonTitle:[WPLanguage get:@"CANCEL"] 
                                              destructiveButtonTitle:nil 
                                                   otherButtonTitles:[WPLanguage get:@"SignupPhotosheetGallery"], camera, nil];
    [photoSheet showInView:self.view];
}

请在这些调用中提供上下文,如果没有看到您的代码,就无法知道发生了什么。我希望您正在与第四个选项卡相关联的视图控制器中调用presentModalViewController而不是在显示标签栏的视图控制器中调用。 - gurooj
如果您的视图控制器由第四个选项卡呈现模态视图,则此问题将得到解决。或者是这种情况吗? - fearmint
@gurooj 我正在第四个选项卡关联的视图控制器中调用presentModalViewController。 @JoePasq 模态视图已经由第四个选项卡呈现,但当我关闭它时,我会跳转到第一个选项卡,我想留在第四个选项卡。 - Baloomba
关于给出的代码,没有明显的错误。但是我希望你正在使用自动引用计数,因为必须释放所有分配的对象,否则会导致内存泄漏。也许这可能是一个问题?无论如何,这需要得到解决。另外,imgPicker.delegate = nil 这一部分似乎有些不对劲。我从未使用过它,并且在使用图像选择器时从未遇到任何问题。 - gurooj
1个回答

4

只是猜测(您需要添加更多细节):您的视图控制器实现了UITabBarDelegate,它是否在viewWillAppear:(或其他调用的方法)中设置了选定项?


1
非常感谢,这就是问题的根源。 - Baloomba

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接