具有多个DetailView的iPad应用程序,并在detailview中有导航

时间:2012-05-15 03:42:02

标签: ios ipad

我在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:]:无法识别的选择器已发送到实例...

showRootPopoverButtonItemRootViewController

中协议中定义的方法
@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

所以提前谢谢。

1 个答案:

答案 0 :(得分:0)

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

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

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

编辑 -

我检查了这一点,发现你做错了什么,例如willHideViewController中的代码 -

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

这是期待一个视图控制器,而你正在传递导航控制器,而导航控制器又有视图控制器(类似于其他位置),所以如果你想从app delegate传递导航控制器,你也需要改变这些代码。