我不认为更改标签栏控制器的 selectedIndex 是一种“肮脏的解决方法”——根据您的设置,这就是这样做的方法。您似乎希望 EntryViewController (Library) 成为 EntryDetailViewController 的代表。如果是这样,您可以在 EntryDetailViewcontroller 的 viewDidLoad 方法中设置委托,如下所示:
#import "DetailViewController.h"
#import "TableController.h"
@interface DetailViewController ()
@property (strong,nonatomic) UITabBarController *tbc;
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tbc = (UITabBarController *)self.presentingViewController;
self.delegate = (TableController *)[(UINavigationController *)self.tbc.viewControllers[1] topViewController];
}
- (IBAction)saveAndUpload:(UIButton *)sender {
[self.tbc setSelectedIndex:1];
[self.delegate saveRecording:@"test recording"];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)delete:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
在我的示例中,我只有两个按钮可以保存或取消,我的 TableController 将与您的库控制器相同。