gpt4 book ai didi

uisplitviewcontroller - 无法使 UIPopover 以编程方式出现

转载 作者:行者123 更新时间:2023-12-04 08:24:35 24 4
gpt4 key购买 nike

我希望弹出窗口在应用程序首次以纵向模式启动时出现,而不是隐藏它并要求用户在弹出窗口出现之前点击按钮。我试图通过 Google 和其他 StackOverflow 线程之类的工具找到解决方案,但我一直无法弄清楚。因此,如果 XCode 创建的标准 SplitView 示例不同,我会将代码放在下面。如果我能让它在这个应用程序上运行,我希望我能理解它并能够将它应用到其他地方。

我想尝试在按下按钮时只调用调用的内容...但我无法弄清楚调用的内容以及声明的位置...我觉得我忽略了一些基本的东西而且它是快把我逼疯了!

细节 View Controller DetailViewController.h

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {

UIPopoverController *popoverController;
UIToolbar *toolbar;

id detailItem;
UILabel *detailDescriptionLabel;
}

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

@property (nonatomic, retain) id detailItem;
@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;

@end

DetailViewController.m

#import "DetailViewController.h"
#import "RootViewController.h"


@interface DetailViewController ()
@property (nonatomic, retain) UIPopoverController *popoverController;
- (void)configureView;
@end



@implementation DetailViewController

@synthesize toolbar, popoverController, detailItem, detailDescriptionLabel;

#pragma mark -
#pragma mark Managing the detail item

/*
When setting the detail item, update the view and dismiss the popover controller if it's showing.
*/
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];

// Update the view.
[self configureView];
}

if (self.popoverController != nil) {
[self.popoverController dismissPopoverAnimated:YES];
}
}


- (void)configureView {
// Update the user interface for the detail item.
detailDescriptionLabel.text = [detailItem description];
}


#pragma mark -
#pragma mark Split view support

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {

barButtonItem.title = @"Root List";
NSMutableArray *items = [[toolbar items] mutableCopy];
[items insertObject:barButtonItem atIndex:0];
[toolbar setItems:items animated:YES];
[items release];
self.popoverController = pc;
}


// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {

NSMutableArray *items = [[toolbar items] mutableCopy];
[items removeObjectAtIndex:0];
[toolbar setItems:items animated:YES];
[items release];
self.popoverController = nil;
}


#pragma mark -
#pragma mark Rotation support

// Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}


#pragma mark -
#pragma mark View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/

/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.popoverController = nil;
}


#pragma mark -
#pragma mark Memory management

/*
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}
*/

- (void)dealloc {
[popoverController release];
[toolbar release];

[detailItem release];
[detailDescriptionLabel release];
[super dealloc];
}

@end

rootview 是一个典型的 UITableViewController 并且没有什么特别的,但是如果出于某种原因你需要它或委托(delegate)(除了加载 View 之外这很无聊)来帮助我解决这个问题我也没有问题发布这些。同样,当我告诉 XCode 我想为 iPad 创建一个 Split View并且我没有修改它时,它直接生成了它。

希望有一些我忽略的非常小的东西,它会让我拍拍我的头说“我不敢相信我错过了!”感谢您的帮助。

最佳答案

想通了!

我放

[self.popoverController presentPopoverFromBarButtonItem:[[toolbar items] objectAtIndex:0] permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

在 ViewDidLoad 方法中。我知道这很简单!它似乎可以正常工作!

关于uisplitviewcontroller - 无法使 UIPopover 以编程方式出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7943589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com