通用应用程序中 UITabBar 内的 UISplitView 未更新详细信息视图

发布于 2024-11-08 13:20:32 字数 2763 浏览 0 评论 0原文

我正在创建一个在 UITabBar 内使用 UISplitView 的通用应用程序。一切工作正常(TabBar 导航、PopOver、SplitView 以纵向和横向显示,...),除了当我从根 SplitView(即 UITableViewController)中选择一个项目时,SplitView 的详细信息视图不会更改...更奇怪的是,只有界面控件不会更新 - 所有变量和方法都被正确调用和使用。

这是我的代码:

AppDelegate.h 中的代码块:

@interface DicionarioAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;   
UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

AppDelegate.m 中的代码块(如果是 iPad):

iPadRootController* rootVC = [[[iPadRootController alloc] initWithNibName:@"iPadSearch" bundle:nil] autorelease];    
    iPadDetailsController* detailsVC = [[[iPadDetailsController alloc] initWithNibName:@"iPadDetails" bundle:nil] autorelease];

    UISplitViewController* splitViewController = [[UISplitViewController alloc] init];
    splitViewController.viewControllers = [NSArray arrayWithObjects:rootVC, detailsVC, nil];
    splitViewController.delegate = detailsVC;
    splitViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Search" 
                                                                   image:[UIImage imageNamed:@"search.png"] 
                                                                   tag:0];

    // Add them as children of the tab bar controller
    tabBarController.viewControllers = [NSArray arrayWithObjects:
                                        splitViewController, 
                                        secondController,
                                        thirdController,
                                        nil];

    [splitViewController release];

iPadRootViewController.h 中的代码块:

@property (nonatomic, retain) iPadDetailsController *detailsController;

iPadRootViewController.m 中的代码块(当选择项目时):

iPadDetailsController *newDetailViewController = [[iPadDetailsController alloc] initWithNibName:@"iPadDetails" bundle:nil];
self.detailsController = newDetailViewController;
self.detailsController.detailItem = id;

iPadDetailViewController.h 中的代码块:

@property (nonatomic, retain) IBOutlet UILabel *someLabel;

以及在iPadDetailsViewController.m中,我可以将detailItem值分配给变量(并且所有方法都有效),但与界面相关的任何内容都保持为空。代码块:

if (detailItem != newDetailItem) {
    [detailItem release];
    detailItem = [newDetailItem retain];
    self.word = [detailItem description];
    self.someLabel.text = [detailItem description];

    //Update the view
    ...
}

在这种情况下,self.word 获得正确的值,但 self.someLabel 文本属性不会(保持为 null)。我是 iPhone/iPad 编程新手,但我相信我正确链接了所有插座。

请帮助我...我快要疯了。任何想法表示赞赏!

我正在使用 XCode 4。 谢谢!

I'm creating an Universal App that uses a UISplitView inside an UITabBar. Everything is working fine (TabBar navigation, PopOver, SplitView showing up in both portrait and landscape,...) except that when I select an item from the Root SplitView (that is a UITableViewController) the Details view of the SplitView won't change... and even more strange, only the interface controls won't update - all the variables and methods are correctly called and used.

Here's my code:

Code block from AppDelegate.h:

@interface DicionarioAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;   
UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

Code block from AppDelegate.m (if iPad):

iPadRootController* rootVC = [[[iPadRootController alloc] initWithNibName:@"iPadSearch" bundle:nil] autorelease];    
    iPadDetailsController* detailsVC = [[[iPadDetailsController alloc] initWithNibName:@"iPadDetails" bundle:nil] autorelease];

    UISplitViewController* splitViewController = [[UISplitViewController alloc] init];
    splitViewController.viewControllers = [NSArray arrayWithObjects:rootVC, detailsVC, nil];
    splitViewController.delegate = detailsVC;
    splitViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Search" 
                                                                   image:[UIImage imageNamed:@"search.png"] 
                                                                   tag:0];

    // Add them as children of the tab bar controller
    tabBarController.viewControllers = [NSArray arrayWithObjects:
                                        splitViewController, 
                                        secondController,
                                        thirdController,
                                        nil];

    [splitViewController release];

Code block from iPadRootViewController.h:

@property (nonatomic, retain) iPadDetailsController *detailsController;

Code block from iPadRootViewController.m (when items gets selected):

iPadDetailsController *newDetailViewController = [[iPadDetailsController alloc] initWithNibName:@"iPadDetails" bundle:nil];
self.detailsController = newDetailViewController;
self.detailsController.detailItem = id;

Code block from iPadDetailViewController.h:

@property (nonatomic, retain) IBOutlet UILabel *someLabel;

And in iPadDetailsViewController.m, I can assign detailItem value to a variable (and all methods are working) but anything that's interface related stays null. Code block:

if (detailItem != newDetailItem) {
    [detailItem release];
    detailItem = [newDetailItem retain];
    self.word = [detailItem description];
    self.someLabel.text = [detailItem description];

    //Update the view
    ...
}

In this case, self.word gets the correct value but self.someLabel text property won't (stays null). I'm new to iPhone/iPad programming but I believe I'm linking all outlets correctly.

Please help me... I'm going nuts on this. Any ideas appreciated!

I'm using XCode 4.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2024-11-15 13:20:32

每次要显示项目时,您都会创建一个新的 iPadDetailsViewController 对象。这个新对象不仅没有被连接,而且也是错误的做法。您必须在应用程序委托中设置 detailsController -

iPadRootController* rootVC = [[[iPadRootController alloc] initWithNibName:@"iPadSearch" bundle:nil] autorelease];    
iPadDetailsController* detailsVC = [[[iPadDetailsController alloc] initWithNibName:@"iPadDetails" bundle:nil] autorelease];
rootVC.detailsController = detailsVC;
...

并且 iPadRootViewController.m 中的代码块将变为 -

self.detailsController.detailItem = id;

You are creating a new iPadDetailsViewController object every time you want to display an item. Not only is this new object not wired in, it is also wrong thing to do. You will have to set the detailsController in the application delegate –

iPadRootController* rootVC = [[[iPadRootController alloc] initWithNibName:@"iPadSearch" bundle:nil] autorelease];    
iPadDetailsController* detailsVC = [[[iPadDetailsController alloc] initWithNibName:@"iPadDetails" bundle:nil] autorelease];
rootVC.detailsController = detailsVC;
...

and the code block in iPadRootViewController.m would become –

self.detailsController.detailItem = id;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文