0

我寻找一种在 iPad 应用程序中拥有多个详细视图的方法,我在苹果开发者网站http://developer.apple.com/library/ios/#samplecode/MultipleDetailViews/Introduction/Intro.html中找到了示例代码,但现在我想在此示例未涵盖的详细视图中进行导航,我将 uinavigationcontroller 添加到详细视图中:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ReportsViewController_iPad *master = [[ReportsViewController_iPad alloc] initWithNibName:@"ReportsViewController_iPad" bundle:nil];

    DetailViewController_iPad *detail = [[DetailViewController_iPad alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];

    UINavigationController *masterNavController = [[[UINavigationController alloc] initWithRootViewController:master ] autorelease];

    UINavigationController *detailNavController = [[[UINavigationController alloc] initWithRootViewController:detail ] autorelease];

    splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavController , detailNavController, nil];

    [window addSubview:splitViewController.view];
    [window makeKeyAndVisible];

    return YES;
}

但是当我运行示例时出现错误

[UINavigationController showRootPopoverButtonItem:]:无法识别的选择器发送到实例...

showRootPopoverButtonItem是在协议中定义的方法RootViewController

@protocol SubstitutableDetailViewController
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
@end

---- ReportsViewController.h

@protocol SubstitutableDetailViewController
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
@end

@protocol DetailViewControllerManagerDelegate

-(void) didSelectRowAtIndexPathPopOver:(NSString *)ID;

@end

@interface ReportsViewController_iPad : ReportsViewController<UISplitViewControllerDelegate , DetailViewControllerManagerDelegate>
{
    UISplitViewController *splitViewController;

    UIPopoverController *popoverController;

    UIBarButtonItem *rootPopoverButtonItem;
}

@property (nonatomic, assign) IBOutlet UISplitViewController *splitViewController;

@property (nonatomic, retain) UIPopoverController *popoverController;

@property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;

@property(nonatomic, retain) id<DetailViewControllerManagerDelegate> delegate;

-(void)didSelectRowAtIndexPath:(NSString*)ID;

@end

--DetailViewController.h

#import <UIKit/UIKit.h>
#import "ReportsViewController_iPad.h"

@interface DetailViewController_iPad : UIViewController<SubstitutableDetailViewController>
{
     UIToolbar *toolbar;
}

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;

@end

--DetailViewController.m

#import "DetailViewController_iPad.h"

@implementation DetailViewController_iPad

@synthesize toolbar;

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

#pragma mark -
#pragma mark Managing the popover

- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {

    // Add the popover button to the toolbar.
    NSMutableArray *itemsArray = [toolbar.items mutableCopy];
    [itemsArray insertObject:barButtonItem atIndex:0];
    [toolbar setItems:itemsArray animated:NO];

    [itemsArray release];
}


- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {

    // Remove the popover button from the toolbar.
    NSMutableArray *itemsArray = [toolbar.items mutableCopy];
    [itemsArray removeObject:barButtonItem];
    [toolbar setItems:itemsArray animated:NO];
    [itemsArray release];
}


- (void)dealloc {
    [toolbar release];
    [super dealloc];
}   

@end

所以提前谢谢。

4

1 回答 1

0

showRootPopoverButtonItem存在方法定义的地方,似乎没有定义。你需要定义它。

如果你想避免崩溃,那么你可以使用 -

if ([aViewController respondsToSelector:@selector(showRootPopoverButtonItem:)]) {
    [aViewController performSelector:@selector(showRootPopoverButtonItem:) withObject:self.rootPopoverButtonItem];
}

编辑 -

我已经检查过了,发现你做错了什么,例如代码willHideViewController-

UIViewController <SubstitutableDetailViewController> *detailViewController =  [splitViewController.viewControllers objectAtIndex:1];

这需要一个视图控制器,而您正在传递导航控制器,而导航控制器又具有视图控制器(在其他位置类似),因此如果您想从应用程序委托传递导航控制器,您还需要更改这些代码。

于 2012-05-15T03:55:32.327 回答