我的 iPhone 导航应用程序中有一个自定义 UIButton 类。当用户单击按钮时,我会显示一个模式视图,该视图显示用户可以从中选择的记录的 tableview 列表。
单击按钮后,我创建了 viewController 并使用以下代码显示它:
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
dropDownPickerViewController = [[DropDownListingViewController alloc] initWithNibName:@"DropDownListingView" bundle:[NSBundle mainBundle]];
.....
.....
[[(AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate] navigationController] presentModalViewController:dropDownPickerViewController animated:NO];
[dropDownPickerViewController release];
[super touchesEnded:touches withEvent:event];
}
如您所见,该按钮可以在任何 viewController 上,因此我从应用程序委托中获取了 navigationController。比在我的 DropDownPickerViewController 代码中,当用户选择记录时,我有以下内容:
[[(AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate] navigationController] dismissModalViewControllerAnimated:NO];
但什么也没有发生。它似乎冻结并挂起,不允许与表单进行任何交互。关于为什么我的 ModalViewController 不会被解雇的任何想法?我认为这是我使用应用程序委托来呈现 viewController 的方式。有没有办法在 UIButton 类中使用 self.ParentViewController 以便我可以获得按钮所在视图的 ViewController(如果这是问题所在)?
任何想法将不胜感激。
谢谢