首先,如果是這樣,不知何故,這是一個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:我很高興,它幫助。不幸的是,我沒有指向教程的鏈接。 –