我会将此作为评论发布,但我无法这样做。
是应该调用dismissModelViewControllerAnimated:的主视图控制器。您可以在呈现的视图控制器中调用[[self parentViewController]dismissModalViewControllerAnimated:]或在协议中定义一个方法来关闭模式视图控制器并在主视图控制器中实现协议,将其设置为呈现的视图控制器的委托并从中调用方法。你做错了。它可能会也可能不会解决您的问题。
更新(评论中没有代码示例):
在 MainViewController 你应该有这样的东西
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// In this case is inside a tableviewmethod, but it could really be an action associated with a button.
DetailViewController *controller = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
[controller setDelegate:self]; // The delegate is the parent and is assigned, not retained.
// Modal presentation style is only used on iPad. On iPhone is always full screen.
// [controller setModalPresentationStyle:UIModalPresentationFullScreen];
[controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:controller animated:YES];
[controller release]; // It will be deallocated upon dismissal.
}
-(void)dismissDetailViewControllerAndProcessData:(NSDictionary *)data {
// Do something with the data passed.
[self processData:data];
// Dismiss the modalviewcontroller associated with this viewcontroller.
[self dismissModalViewControllerAnimated:YES];
}
而在作为模态视图控制器呈现的详细视图控制器上,唯一需要的是这样的东西
-(void)actionBack:(id)sender {
// Call the delegate method. If you just need to dimiss the controller, just
// call
// [[self parentViewController]dismissModalViewControllerAnimated:YES];
// and don't even bother to set up a delegate and a delegate method.
[delegate dismissDetailViewControllerAndProcessData:nil]; // Call the parent dismissal method.
}
但如果应用程序在 iPhone 上运行良好,它在 iPad 上的运行应该与 iPhone 应用程序一样好。