首先,如果是这样,不知何故,这是一个dup帖子,随时可以指向正确的一个,因为在搜索几小时后我还没有找到它。当使用push segue时,主应用程序会立即崩溃
我在我的应用程序中使用了一个MasterDetail viewController,在开发的第一个星期左右,没有其他ViewVontrollers或除默认外的其他Seglog。我写了我的主代码,Master和Detail viewController工作正常。一旦我从详细视图中添加了另一个VC push push,我的应用程序立即崩溃。这是错误:
***Terminating app due to uncaught exception 'NSInvalidArgumentException', reason '-[UINavigationController setPlayer:]: unrecognized selector sent to instance ...'
然后一堆十六进制。
在AppDelegate.m,如果我注释掉这一行:
rightViewController.delegate = rightViewController
然后应用程序将启动,并推动SEGUE的工作,但现在,很明显,如果我选择在MasterView中,它会崩溃给这个错误:
***Terminating app due to uncaught exception 'NSInvalidArgumentException', reason '-[UINavigationController selectedPlayer:]: unrecognized selector sent to instance ...'
然后一堆十六进制。
这里是所有的代码,我认为是相关的:
AppDelegate.m
#import "AppDelegate.h"
#import "LeftViewController.h"
#import "RightViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *leftNavController = [splitViewController.viewControllers objectAtIndex:0];
LeftViewController *leftViewController = (LeftViewController *)[leftNavController topViewController];
RightViewController *rightViewController = [splitViewController.viewControllers objectAtIndex:1];
Player *selectedPlayer = [[leftViewController preclears]objectAtIndex:0];
[rightViewController setPlayer:selectedPlayer];
leftViewController.delegate = rightViewController;
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
LeftViewController.m(部分)
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//Re-fetch the feed from the Postgres Database when a user selects an entry
[JSONHTTPClient getJSONFromURLWithString:@"http://myurl" completion:^(NSDictionary *json, JSONModelError *err) {
NSError* error = nil;
_feed = [[PostgresFeed alloc] initWithDictionary:json error:&error];
//Print the data fethced to NSLog in JSON format
[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:nil userInfo:[[json objectForKey:@"player"] objectAtIndex:indexPath.row]];
}];
Player *selectedPlayer = [_players objectAtIndex:indexPath.row];
if (_delegate)
{
[_delegate selectedPlayer:selectedPlayer];
}
}
所以,我我做错了什么,但我无法弄清楚它是什么。我做了大量的搜索,但还没有找到答案。如果有人想知道,我是iOS和Obj C的新手,MasterDetail应用程序基于iPad SplitViews的Ray Wenderlich教程。我也检查了一些关于segges的Scott Sherwood教程,但在那里没有找到任何答案。
让我知道是否需要更多的代码。
@CaptJak:我很高兴,它帮助。不幸的是,我没有指向教程的链接。 –