gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 05:46:56 25 4
gpt4 key购买 nike

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

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

代码:

父 View

-(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: 的位置以及 View 何时被关闭。

最佳答案

我在发布赏金后几个小时内解决的数字!

问题是 fetchEntries 方法(我没有发布它,因为我认为它不是罪魁祸首)在完成对服务器的调用时将分段控件的选定索引设置为 -1。如果 EventValueChanged 更改为 -1,较新版本的 iOS 似乎会忽略它。我只是在 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];
}

}

关于iphone - 模态视图重新出现 + 崩溃 : "Attempting to transition while a transition is in progress",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10091256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com