模态视图重新出现 + 崩溃:"Attempting to transition while a transition is in progress"



让我提供一些上下文:我正在构建一个选项卡式应用程序,允许用户查找和查看我们服务器上托管的一些视频。每个选项卡都以不同的方式对视频进行分组,导航栏中有一个分段控件,用户可以使用该控件对列表进行更精确的排序(按标题、日期等)。在分段控件中点击"排序"后,将显示一个模式视图控制器,其中包含特定选项卡上的可用选项。选择一个选项,并将该选择中继回父视图控制器,该控制器在服务器上调用排序列表。

现在问题是:在我们想要支持的iOS 4.2上,模态视图要么在选择排序选项后崩溃,要么关闭,然后立即再次出现。如果它再次出现,它只会这样做一次,并且不会无限期循环。我知道这与过渡和视图的生命周期有关,但我似乎无法正确理解这一点。

法典:

父视图

-(void) segmentAction:(id)sender{
    //create a sort view and pass it a value that indicates what the options should be
    ModalSortViewController *sortView = [[ModalSortViewController alloc]    
                                        initWithNibName:nil bundle:nil sortByView:0];
    [sortView setDelegate:self];
    [sortView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    [sortView setModalPresentationStyle:UIModalPresentationFormSheet];
    [self presentModalViewController:sortView animated:YES];
}
-(void) refresh:(id)sender{
    [self fetchEntries];
}
//Delegate protocol for all tabbed table views
//Receives buttonIndex from the modal sort view
-(void)sortByButtonIndex:(int)buttonIndex{
    if(buttonIndex==1){
        //If sorting by title
        fetchURL = @"fakeURL.com/?method=iGetCategories&sortBy=category&sortByOrder=ASC";
        [self fetchEntries];
    }
    else if (buttonIndex==2){
        //If sorting by number of items
        fetchURL = @"fakeURL.com/?method=iGetCategories&sortBy=count&sortByOrder=DESC";
        [self fetchEntries];
    }
    else if(buttonIndex==0){
        //Resets sort selection to nothing
        segmentedControl.selectedSegmentIndex = -1;
    }
    [self dismissModalViewControllerAnimated:YES];
}

模态视图

@synthesize delegate, option1, option2;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil sortByView:(int)_viewInt
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        sortChosen = 0;
        viewInt = _viewInt;
    }
    return self;
}
//This method is called whenever a selection on the modal view has been made.
//The button tags have been set in IB and are sent to the parent table view controller
//where a switch statement is in place to sort its data by the selection.
-(IBAction)madeSelection:(id)sender{
    sortChosen = [sender tag];
    [self.delegate sortByButtonIndex:sortChosen];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];//Added after Felix pointed out that the super was not called
    switch (viewInt) {
        case CAT_FOLDERS:
            [self.option1 setTitle:@"By Category Name" forState:UIControlStateNormal];
            [self.option2 setTitle:@"By Number of Items" forState:UIControlStateNormal];
            break;
        case PRES_FOLDERS:
            [self.option1 setTitle:@"By Presenter Name" forState:UIControlStateNormal];
            [self.option2 setTitle:@"By Number of Items" forState:UIControlStateNormal];
            break;
        case MEDIA:
            [self.option1 setTitle:@"By Media Title" forState:UIControlStateNormal];
            [self.option2 setTitle:@"By Release Date" forState:UIControlStateNormal];
            break;
        default:
            break;
    }
}

崩溃结果:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Attempting to begin a modal transition from <UINavigationController: 
0x139160> to <ModalSortViewController: 0x172810> while a transition is already in
progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'

对不起长度。我想尽可能清晰和彻底。提前谢谢你!

编辑:我应该提到崩溃/重复出现似乎取决于调用sortByButtonIndex:的位置以及视图何时被关闭。

数字 我会在上面发布赏金后解决这个小时!

问题是 fetchEntries 方法(我没有发布,因为我认为它不是罪魁祸首)在完成对服务器的调用时将分段控件的选定索引设置为 -1。似乎较新版本的iOS忽略了事件值更改,如果它更改为-1。我只是设置了一个条件来忽略 segmentAction: 方法中分段控件上的 -1 索引,它就可以工作了。

-(void) segmentAction:(id)sender{
    if(segmentedControl.selectedIndex != -1){
        //create a sort view and pass it a value that indicates what the options should be
        ModalSortViewController *sortView = [[ModalSortViewController alloc]    
                                        initWithNibName:nil bundle:nil sortByView:0];
        [sortView setDelegate:self];
        [sortView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
        [sortView setModalPresentationStyle:UIModalPresentationFormSheet];
        [self presentModalViewController:sortView animated:YES];
    }
}

您不是从-(void)viewWillAppear:(BOOL)animated内部调用super

尝试在顶部添加以下行:

[super viewWillAppear:animated];

这可能意味着视图控制器的超级实现未正确设置其显示标志。

最新更新