我有一堂课RootViewController
,我有一个UIBarButtonItem
声明。显示它的方法在另一个类FirstDetailViewController
中。
我试图在另一个类中访问它SecondDetailViewController
,但它始终为空。我用其他一些变量进行了测试,它们也为空。这是我所拥有的:
RootViewController.h
@interface RootViewController : UITableViewController <UISplitViewControllerDelegate> {
}
@property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;
...
@end
根视图控制器.m
#import "RootViewController.h"
#import "FirstDetailViewController.h"
@implementation RootViewController
@synthesize popoverController, splitViewController, rootPopoverButtonItem;
- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc {
NSLog(@"splitviewController will hide");
// Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.
barButtonItem.title = @"Menu";
self.popoverController = pc;
self.rootPopoverButtonItem = barButtonItem;
UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
[detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];
}
FirstDetailViewController.m
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
NSLog(@"show root popover button item");
// Add the popover button to the toolbar.
NSMutableArray *itemsArray = [toolbar.items mutableCopy];
[itemsArray insertObject:barButtonItem atIndex:0];
[toolbar setItems:itemsArray animated:NO];
[itemsArray release];
}
SecondDetailViewController.h
#import "RootViewController.h"
@class RootViewController;
@interface SecondDetailViewController : UIViewController <SubstitutableDetailViewController, UIScrollViewDelegate, UITextFieldDelegate, UITextViewDelegate> {
...
}
@property (nonatomic, retain) RootViewController *root;
@end
SecondDetailViewController.m
#import "SecondDetailViewController.h"
@implementation SecondDetailViewController
@synthesize root;
...
NSLog(@"view class : %@", [root.splitViewController class]);
[detailViewController showRootPopoverButtonItem:root.rootPopoverButtonItem];
...