0

我有一个工作项目,其中一个屏幕是例如ViewController 1 - tableView。在 ViewController 1 中选择一行后,我正在尝试传递数据并导航到ViewController 2。我添加了以下代码:

DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedItem = selectedItem;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];

但它没有传递给ViewController 2。我认为问题出在 navigatorController 上。我应该在哪里添加它?到 ViewController 1 的 xib 文件?或 mainAppDelegate - 我不想碰它,因为它已经在使用它的设置......

我在 appDelegate 中声明了 UINavigationController *navigationController

我应该检查什么?

在对代码进行一些更改后(感谢@Vakul Saini)appDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.View1 = [[startSearching alloc] initWithNibName:@"StartSearching" bundle:nil];
self.currentNC = [[UINavigationController alloc] initWithRootViewController:self.View1];

//this line start the startSearching at the begining and its passing to //secondViewController
    self.window.rootViewController = self.currentNC;

// 但是这一行是从原始起始页面开始的,但是视图的转移 // 不起作用

 [self.window setRootViewController: self.viewController];

appDelegate.h

@property (strong, nonatomic) startSearching *View1;
@property (strong, nonatomic) UINavigationController *currentNC;

开始搜索.m

detailCon *detailCo =[[detailCon alloc] initWithNibName: @"detailView" bundle: [NSBundle mainBundle]];
[detailCon release];
UINavigation *currentNC1 = [[AppDelagate sharedInstance] currentNC];
[currentVC1 pushViewController:detailCo animated:YES];
4

1 回答 1

1

检查你是否有UINavigationController一个Appdelegate。你需要让你的应用程序rootViewControllerUINavigationController Add your UINavigationControllerinappdelegate

Appdelegate.h 文件

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UINavigationController *navCon;

@end

Appdelegate.m 文件

#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize navCon = _navCon;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.navCon = [[UINavigationController alloc]initWithRootViewController:self.viewController];
    self.window.rootViewController = self.navCon;
    [self.window makeKeyAndVisible];
    return YES;
}

ViewController您的应用程序的第一个视图在哪里。

于 2012-08-18T13:02:12.747 回答