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

时间:2011-05-20 16:37:47

标签: iphone ios ipad uitabbarcontroller uisplitviewcontroller

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

这是我的代码:

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值分配给变量(并且所有方法都正常工作)但是接口相关的任何内容都保持为null。代码块:

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。 谢谢!

1 个答案:

答案 0 :(得分:0)

每次要显示项目时,都要创建一个新的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;