继承QLPreviewController,点击“Home”后,navigationItem上的更改按钮被重置

时间:2012-05-10 13:46:30

标签: iphone objective-c ios uinavigationitem qlpreviewcontroller

我们有一个自定义的QLPreviewController实现,因此我们可以控制呈现给用户的按钮及其操作。 我已将以下代码添加到自定义类的viewWillAppear方法中:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(openWithPressed:)];
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissPressed:)];
    [self.navigationItem setRightBarButtonItem:rightBarButtonItem];
    [self.navigationItem setLeftBarButtonItem:leftBarButtonItem];
    [rightBarButtonItem release];
    [leftBarButtonItem release];
}

预览器会显示我们的自定义按钮,它们按预期工作 当用户单击“主页”按钮时,会出现问题。它会UIApplication.doEvents方法调用navigationItem设置按钮方法,并将它们重置为原始值(使用原始处理程序)。
如何防止这种情况发生,或者自己处理这些事件,并使用我自己的自定义按钮覆盖它们?

1 个答案:

答案 0 :(得分:2)

我有同样的问题。您需要设置一个在应用程序再次激活时调用的NSNotification,然后将导航栏重置为您希望的方式

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(configureNavBar)
                                             name:UIApplicationDidBecomeActiveNotification object:nil];
相关问题