我创建了一个字典应用程序,我使用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;
}
segue的目标控制器已经是您的'MeaningViewController',而不是导航控制器。 – rmaddy
@rmaddy这是什么意思:'MeaningViewController * meaningVC =(MeaningViewController *)[[segue destinationViewController] topViewController];'仍然崩溃! –
你想要:'MeaningViewController * meaningVC =(MeaningViewController *)[segue destinationViewController];' – rmaddy