【问题标题】:iPhone Xcode - Navigation Controller on second xib view?iPhone Xcode - 第二个xib视图上的导航控制器?
【发布时间】:2010-04-13 15:29:23
【问题描述】:

一切都很好,我的导航控制器显示的是我的“菜单 1”项,但是当我单击它时,似乎出现了问题:

[self.navigationController pushViewController:c 动画:YES];行它不连接到 myClass 文件中的断点。所以我想我还没有加入什么?但不确定是什么?

我使用导航控制器的第二个视图无法直接访问 AppDelegate,因此无法像在某些教程中看到的那样加入它。

点击调用时,第一个视图只是一个按钮:

[self presentModalViewController:mainViewController animated:YES];

我的第二个视图“MainViewController”标题如下:

@interface MainViewController :UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
    NSArray *controllers;
    UINavigationController *navController;
}

@property (nonatomic, retain) IBOutlet UINavigationController *navControllers;

@property (nonatomic, retain) NSArray *controller;

然后我有我的 MainViewController.m

@synthesize controllers;
@synthesize navController;

- (void) viewDidLoad
{
    NSMutableArray *array = [[NSMutaleArray alloc] init];
    myClass *c = [[myClass alloc] initWithStyle:UITableViewStylePlain];
    c.Title = @"Menu 1";

    [array addObject:c];
    self.Controllers = array;
    [array release];
}

实现 numberOfRowsInSection 和 cellForRowAtIndexPath

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSUInteger row = [indexPath row];
    myClass *c = [self.controllers objectAtIndex:row];
    [self.navigationController pushViewController:c animated:YES]; // doesn't load myClass c
    // [self.navController pushViewController:c animated:YES];
}

同样在 Interface Builder 中,我将一个 Navigation Controller 拖到我的新 XIB 上,并将 Root View Controller 类更改为 MainViewController,并将 File Owner 连接器连接到 Navigation Controller 以连接 navController Outlet。

感谢您的宝贵时间。

【问题讨论】:

  • 到底是什么问题?什么“myClass 文件中的断点”?
  • 当我声明一个数组并将其绑定回导航控制器时,myClass 的第一行 -(void) viewDidLoad。希望这会有所帮助。
  • 那么您粘贴在这里的所有代码都可以正常工作吗?问题是MyClass(似乎是UITableViewController的子类)中的方法viewDidLoad永远不会被调用?如果问题出在哪里,也许您应该发布该类的代码。

标签: iphone xcode


【解决方案1】:

myClass.h

#import "SecondLevelViewController.h" //This inherts UITableViewController

@class myClass;

@interface myClass : SecondLevelViewController
{
NSArray *list;
myClassDetail *detail;
}
@property (nonatomic, retain) NSArray *list;

myClass.m

#import "myClass.h"
#import "myClassDetail.h"
#import "NavAppDelegate.h"

@implementation myClass
@systjesize list;

- (void) viewDidLoad
{
  NSArray *array = [[NSArray alloc] initWithObjects:@"test1",@"test2",nil];
self.list = array;
.. .. ..
//I can't get a break point at this point or in any of the other methods
}

所以在这个页面中没有找到断点告诉我我错过了一些东西。由于这是与 MainWindow.XIB 分开的 XIB 文件,因此我无权访问 App Delegate。

所以当我在界面构建器中没有应用程序委托时,我真的需要知道如何将导航控制器连接到第二个视图 XIB 文件。所有教程都显示导航控制器连接到此应用程序委托。

程序编译文件并运行,我得到列表中的第一个“菜单 1”,但是当我尝试使用新的 myClass 菜单项“测试 1”、“测试 2”重新填充相同的导航列表时 它没有命中事件 viewDidLoad。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2011-08-22
    • 2015-08-02
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多