当我试图实现在主机和细节与NavigationController一个SplitViewController。我一直在关注this tutorial,但是我仍然遇到一个相当奇怪的问题。 当我尝试拨打代表方法时,我收到-[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 I`ve得到
#import "StudentSelectionDelegate.h"
@interface StudentDetail : UITableViewController <StudentSelectionDelegate>
...
StudentDetail.m
@synthesize SentStudent;
...
-(void)selectedStudent:(Student *)newStudent
{
[self setStudent:newStudent];
}
StudentList表示SPLITVIEW的主人。在StudentList.h I`ve有:
#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我一直在寻找解决方案几个小时。
是'rightViewController'真的'StudentDetail'实例?当你调用'selectedStudent:'记录委托的类,看看你是否有正确的对象类型。 –
你有什么原因重新发明轮子?Xcode Master-Detail应用程序模板已经正确地做到了这一点。 –
@PetahChristian他在学习。重新创造轮子是学生做的。 – trojanfoe