我正在使用 XCode 4.3.2 版创建 iPad 应用程序。我无法弄清楚如何关闭在情节提要中创建的弹出框。
在我的主屏幕上,我有一个按钮。在情节提要上,我从那个按钮到我的弹出框定义了一个segue。我的弹出框是一个表格视图控制器。在弹出框表视图中选择一个项目后,我将所选信息发送回父级并尝试关闭弹出框。一切正常,除了我无法关闭弹出窗口。
主屏幕 .m 文件的代码:
#import "SectionViewController.h"
#import "SortByTableViewController.h"
@interface SectionViewController () <SortByTableViewControllerDelegate>
@end
@implementation SectionViewController
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"DisplaySortByOptions"])
{
SortByTableViewController *popup = (SortByTableViewController*)segue.destinationViewController;
popup.selectedSection = self.selectedSection;
popup.receivedOption = self.selectedItemCharacteristic;
popup.delegate = self;
}
}
- (void)sortByTableViewController:(SortByTableViewController *)sender
returnedOption:(ItemCharacteristic *)returnedOption
{
if(!returnedOption)
{
[self.sortByButton setTitle:@"SHOW ALL" forState:UIControlStateNormal];
}
else
{
[self.sortByButton setTitle:returnedOption.name forState:UIControlStateNormal];
}
self.itemCharacteristic = returnedOption;
[self dismissViewControllerAnimated:YES completion:nil]; //THIS DOES NOT CLOSE THE POPOVER
}
popover .h 文件的代码:
#import <UIKit/UIKit.h>
@class SortByTableViewController;
@protocol SortByTableViewControllerDelegate <NSObject>
- (void)sortByTableViewController:(sortByTableViewController *)sender
returnedOption:(ItemCharacteristic *)returnedOption;
@end
@interface SortByTableViewController : UITableViewController
@property (nonatomic, strong) Section *selectedSection;
@property (nonatomic, strong) ItemCharacteristic *receivedOption;
@property (nonatomic, weak) id <SortByTableViewControllerDelegate> delegate;
@end
popover .m 文件的代码:
#import "SortByTableViewController.h"
@interface SortByTableViewController () <UITableViewDelegate>
@end
@implementation SortByTableViewController
@synthesize selectedSection = _selectedSection;
@synthesize receivedOption = _receivedOption;
@synthesize delegate = _delegate;
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ItemCharacteristic *itemCharacteristic = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self.delegate sortByTableViewController:self returnedOption:itemCharacteristic];
[self dismissViewControllerAnimated:YES completion:nil]; //THIS DOESN'T WORK
[self.navigationController popViewControllerAnimated:YES]; //THIS DOESN'T WORK EITHER
}
@end
感谢您的任何帮助或指导。