让我提供一些上下文:我正在构建一个选项卡应用程序,允许用户查找和查看托管在我们服务器上的一些视频。每个选项卡都以不同的方式对视频进行分组,导航栏中有一个分段的控件,用户可以使用该控件对列表进行更精确的排序(按标题、日期等)。当单击分段控件中的“排序”时,将在特定选项卡上显示带有可用选项的模态视图控制器。选择一个选项,并将选择转发回父视图控制器,父视图控制器在服务器上调用排序列表。
现在有个问题:在我们想要支持的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:被调用的位置和视图何时被取消。
发布于 2012-04-13 21:22:40
在我发布悬赏后的这几个小时我就能解决这个问题了!
问题是,我没有发布fetchEntries方法,因为我不认为它是罪魁祸首,当它完成对服务器的调用时,将已分段控件的选定索引设置为-1。如果iOS更改为-1,则较新版本的EventValueChanged似乎会忽略它。我只设置了一个条件来忽略segmentAction: method中分段控件上的a-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];
}
}发布于 2012-04-10 15:14:46
您不能从super内部调用-(void)viewWillAppear:(BOOL)animated。
尝试在顶部添加以下一行:
[super viewWillAppear:animated];这可能意味着ViewController的超级实现没有正确设置它的出现标志。
https://stackoverflow.com/questions/10091256
复制相似问题