我正在尝试在 master 和 detail 中实现一个带有 NavigationController 的 SplitViewController。我一直在关注本教程,但是我仍然遇到了一个相当奇怪的问题。当我尝试调用委托方法时,我得到-[UINavigationController selectedStudent:]: unrecognized selector sent to instance...
任何帮助将不胜感激。
这是代码:
StudentSelectionDelegate.h
#import <Foundation/Foundation.h>
@class Student;
@protocol StudentSelectionDelegate <NSObject>
@required
-(void)selectedStudent:(Student *)newStudent;
@end
StudentDetail 表示拆分视图中的细节。在 StudentDetail.h 我有
#import "StudentSelectionDelegate.h"
@interface StudentDetail : UITableViewController <StudentSelectionDelegate>
...
StudentDetail.m
@synthesize SentStudent;
...
-(void)selectedStudent:(Student *)newStudent
{
[self setStudent:newStudent];
}
StudentList 代表拆分视图的主人。在 StudentList.h 我有:
#import "StudentSelectionDelegate.h"
...
@property (nonatomic,strong) id<StudentSelectionDelegate> delegate;
在 StudentList.m 中didSelectRowAtIndexPath
[self.delegate selectedStudent:SelectedStudent];
并且没有“SelectedStudent”不为空
最后是 AppDelegate.m
#import "AppDelegate.h"
#import "StudentDetail.h"
#import "StudentListNew.h"
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *leftNavController = [splitViewController.viewControllers objectAtIndex:0];
StudentListNew *leftViewController = (StudentListNew *)[leftNavController topViewController];
StudentDetail *rightViewController = [splitViewController.viewControllers objectAtIndex:1];
leftViewController.delegate = rightViewController;
return YES;
}
PS我一直在寻找解决方案几个小时。