當我試圖實現在主機和細節與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