の問題私が辞書アプリケーションを作成していると私は、検索ワードを選択するために、UISplitViewController
を使用しています、私のアプリケーションがクラッシュし、このログを持つ:ここで持つUISplitViewController
-[MeaningViewController topViewController]: unrecognized selector sent to instance 0x7f918945bef0
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MeaningViewController topViewController]: unrecognized selector sent to instance 0x7f918945bef0'
が私のコードです:ViewController (MasterView)
で :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
[_searchbar resignFirstResponder];
if ([segue.identifier isEqualToString:@"Meaning"]) {
//MeaningViewController *meaningVC = (MeaningViewController*)[[segue destinationViewController] topViewController];
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
MeaningViewController *meaningVC = (MeaningViewController *)navController.topViewController;
NSIndexPath*indexPath = _tableview.indexPathForSelectedRow;
AppDelegate *appDelegateClass = (AppDelegate *)[[UIApplication sharedApplication] delegate];
Reader *selectedWord = [[appDelegateClass wordList] objectAtIndex:indexPath.row];
sqlite3 *database;
NSString *mean = @"";
if (sqlite3_open([appDelegateClass.currentDBPath cStringUsingEncoding:NSUTF8StringEncoding], &database) == SQLITE_OK) {
NSString *sql =[NSString stringWithFormat:@"SELECT MEAN from DICM WHERE id = %ld",(long)selectedWord.oid];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sql UTF8String] , -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
const char* f1 = (const char*)sqlite3_column_text(compiledStatement, 0);
mean = f1 == NULL ? nil : [[NSString alloc] initWithUTF8String:f1];
}}}
readerClass = (Reader *)[appClass.wordList objectAtIndex:indexPath.row];
[meaningVC setGetWord:readerClass.Name];
[meaningVC setGetMeaning:mean];
[meaningVC setGetOid:readerClass.oid];
dbClass=[[DB alloc]init];
[dbClass setViewTime:readerClass.oid];
NSLog(@"mean is %@",readerClass.Name);
}
}
とMeaningViewController (Detail)
で:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[_word setText:_getWord];
[_mean setText:_getMean];
oid = _getOid;
}
問題は、この行が付属しています:
UINavigationController *からNavController =(UINavigationController *)segue.destinationViewController。MeaningViewController * meaningVC =(MeaningViewController *)navController.topViewController;
私はこれでライン上で交換する場合:
MeaningViewController *meaningVC = (MeaningViewController*)segue.destinationViewController;
それが正常に動作しますが、それは細部がちょうど私がこの問題を解決するにはどうすればよいMaster View
にビューコントローラをプッシュし、それを表示代わるものではありませんか?ここ
はAppDelegate
コードです:私は見ることができます
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
splitViewController.delegate = self;
return YES;
}
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
{
return YES;
}
セグの宛先コントローラはナビゲーションコントローラではなく、すでに「MeaningViewController」です。 – rmaddy
@rmaddyこれはどうでしょうか? 'MeaningViewController * meaningVC =(MeaningViewController *)[[segue destinationViewController] topViewController];'まだクラッシュします! –
あなたは次のようにします: 'MeaningViewController * meaningVC =(MeaningViewController *)[segue destinationViewController];' – rmaddy