尝试修复此错误:找不到映射的图像 UIPickerViewFrameLeft-162-Popover.png

2024-05-06

我正在尝试以编程方式创建 uiPickerView 并将其添加到视图中,而不使用界面生成器。不要误会我的意思,我喜欢 IB,但我想这样做的原因是因为我正在尝试构建一个对象,我可以快速插入该对象以使用 UIPopoverViewController 和各种不同的子视图生成弹出菜单(例如 uiPickerView)作为弹出菜单中的菜单。我已经通过在 IB 中构建菜单并使用其 ViewController 初始化弹出窗口来完成这项工作,所以我知道这在很大程度上是如何工作的。

我在下面输入了相关代码,这是我运行它时遇到的两个错误: - “找不到映射图像 UIPickerViewFrameRight-162-Popover.png” - “找不到映射图像 UIPickerViewFrameLeft-162-Popover.png”

我不知道这些图像是什么,但我假设它们是选择器视图的 png。

menu = [[UIPickerView alloc]initWithFrame:CGRectMake(0,100,162,162)];
  menu.delegate = self;
  menu.dataSource = self;

  [menu reloadAllComponents];
  [menu selectRow:0 inComponent:0 animated:YES];

  //Add the picker to the view
  [customViewController.view addSubview:menu];

  popView = [[UIPopoverController alloc] initWithContentViewController:customViewController] ;
  [popView setDelegate:self];
  CGRect pos = [rootView frame];
  [popView presentPopoverFromRect:CGRectMake(pos.origin.x,pos.origin.y,0,pos.size.height) 
         inView:displayView permittedArrowDirections:arrowDir animated:YES];

现在,这段代码将使程序崩溃,除非您删除我尝试将选择器添加到视图的行,此时我只会得到空白的弹出窗口。所以我知道是选择器导致了这个问题,但我不知道如何解决它。我已经搜索了一整天,但 uipickers 上的每个在线教程都包含使用 IB。我的猜测是,这是一个非常愚蠢的错误,比如缺少导入或其他东西,但如果有人能告诉我我做错了什么,我将不胜感激。

另请注意,我遵循了有关如何为 UIPickerView 设置 dataSource 和委托方法的教程,我很确定它们没问题,但是如果您想在这里验证的话:再次感谢。

#import "PopUpMenuViewController.h"



@implementation PopUpMenuViewController

@synthesize menuType;
@synthesize data;
@synthesize popView;
@synthesize menu;
@synthesize customViewController;

#pragma mark -
#pragma mark UIPOPOVERCONTROLLER DELEGATE METHODS
#pragma mark -

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{

 //Delegate this too the User of this class
 return TRUE;
}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{

 //Delegate this too the User of this class
}

#pragma mark -
#pragma mark CUSTOM POPOVERVIEWCONTROLLER METHODS
#pragma mark -

-(void) initWithMenuType:(int)type{

 menuType = type;
}

-(id) initWithMenuType:(int)type andData:(NSMutableArray *)dataSet fromViewItem:(id)sender 
    withMainView:(UIView *)mView{

 [super init];
 menuType = type;
 data = dataSet;
 rootView = sender;
 displayView = mView;
 arrowDir = UIPopoverArrowDirectionUp;
 customViewController = [[UIViewController alloc] initWithNibName:@"PopUpMenu" bundle:nil];

 return self;
}

-(void) setPopUpArrowDirection:(UIPopoverArrowDirection) arrow{

 arrowDir = arrow; 
}


-(void) showPopUp{ 

 //UIPicker Menu
 if (menuType==1) {

  //UIPicker Setup
  menu = [[UIPickerView alloc]initWithFrame:CGRectMake(0,100,162,162)];
  menu.delegate = self;
  menu.dataSource = self;

  [menu reloadAllComponents];
  [menu selectRow:0 inComponent:0 animated:YES];

  //Add the picker to the view
  [customViewController.view addSubview:menu];

  popView = [[UIPopoverController alloc] initWithContentViewController:customViewController] ;
  [popView setDelegate:self];
  CGRect pos = [rootView frame];
  [popView presentPopoverFromRect:CGRectMake(pos.origin.x,pos.origin.y,0,pos.size.height) 
         inView:displayView permittedArrowDirections:arrowDir animated:YES];
  //[popView setPopoverContentSize:CGSizeMake(menu.frame.size.width+5,menu.frame.size.height+5)];

 }


}

#pragma mark -
#pragma mark VIEW CONTROLLER DELEGATE METHODS
#pragma mark -

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
 // Custom initialization.
 }
 return self;
 }
 */

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */

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

 }*/

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (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)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
 [data release];
 [popView release];
 [menu release];
 [rootView release];
 [displayView release];
 [customViewController release];

}

#pragma mark -
#pragma mark UIPICKERVIEW DELEGATE & DATASOURCE METHODS
#pragma mark -

#pragma mark -
#pragma mark UIPickerViewDataSource Methods

- (NSInteger) pickerView: (UIPickerView *) pickerView numberOfRowsInComponent: (NSInteger) component {

 return [data count];
}

- (NSInteger) numberOfComponentsInPickerView: (UIPickerView *) pickerView {

 return 1;
}

#pragma mark -
#pragma mark UIPickerViewDelegate Methods



// Row height in pixels
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {

 return 40.0f;
}

// Column width in pixels
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {

    return 90.0f;
}

- (NSString *) pickerView: (UIPickerView *) pickerView titleForRow: (NSInteger) row 
    forComponent: (NSInteger) component {

 return [data objectAtIndex:row];
}


- (void) pickerView: (UIPickerView *) pickerView 
    didSelectRow: (NSInteger) row inComponent: (NSInteger) component {
}

如果其他人在控制台中遇到此特定警告“无法找到映射图像 UIPickerViewFrameRight-162-Popover.png”,我想我已经弄清楚它出现的原因。

HIG 粗略地表明 UIPickerView 只能添加到 iPad 上的 Popover 中。

“在 iPad 上,仅在弹出窗口中显示日期和时间选择器。”

http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html

在我的实验中,UIPickerView 必须是弹出窗口中当前 UIViewController 的直接且唯一的视图。如果 UIPickerView 出现在视图层次结构中的其他位置,则会出现警告,并且 UIPickerView 看起来会很糟糕(就像缺少视图的左侧部分和右侧部分一样)。

在上面的代码中,您可以看到 UIPickerView 被添加为 customController 中 rootView 的子视图:

[customViewController.view addSubview:menu];

如果 UIPickerView 是 customController 中的根视图,这可能会起作用。

您可以通过重写控制器的 loadView 方法并将 UIPickerView 直接分配给控制器的根视图,以编程方式使 UIPickerView 成为控制器的根视图:

- (void)loadView {
  CGRect frame = CGRectMake(0,0, 300, 300);
  UIPickerView *v = [[[UIPickerView alloc] initWithFrame:frame] autorelease];
  v.delegate = self;   // assuming controller adopts UIPickerViewDelegate 
  v.dataSource = self; // assuming controller adopts UIPickerViewDataSource 

  self.view = v;
}

希望这对某人有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试修复此错误:找不到映射的图像 UIPickerViewFrameLeft-162-Popover.png 的相关文章

  • 动态增加UITableViewCell中UILabel的高度?

    我有一个 UITableView 其中显示一个自定义单元格 我的单元格有两个标签和一个视图 如下图所示 我已经像这样给出了左视图的约束 项目标签限制 中心视图约束 右视图的约束 I am using a bean class to stor
  • 循环缓冲区录音 iOS:可能吗?

    我的一个客户想要连续录制音频 当他单击 提交 时 他只想提交最后 10 秒的内容 所以他想要连续记录并且只保留最后 x 秒 我认为这需要类似循环缓冲区的东西 但是 作为 iOS 的新手 它看起来像AVAudioRecorder只能写入文件
  • iOS App Today 扩展未上传到物理设备

    我正在为我的应用程序创建一个今日小部件http budgt ch http budgt ch因为一些用户要求快速访问关键功能 初步 扩展在 iOS 模拟器上运行良好 安装如下 1 安装最新的容器应用程序 2 安装以 今天 为容器的扩展 但是
  • 保存录制的 AVAudioRecorder 声音文件:现在怎么办? (iOS、Xcode 4)

    在我的应用程序中 我希望用户能够录制一个声音文件并播放它 然后保存该声音文件以供以后使用 我用了本教程 http www techotopia com index php Recording Audio on an iPhone with
  • UITableview 中的水平和垂直滚动[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 I want to make a lineup for a festival You can see what I want to a
  • 在 Objective-C 中比较 2 个字符串

    我写了以下代码 if depSelectedIndice gt 1 comSelectedIndice gt 1 NSLog depart elemet d depSelectedIndice NSLog depart elemet d c
  • 从 UIImagePickerController 相机视图推送 viewController

    我正在开发一款消息应用程序 类似于 WhatsApp 用户可以互相发送文本和图像消息 当用户想要发送图像时 他可以从相机胶卷中选择一张图像 也可以用相机拍摄一张图像 这就是我介绍的方式UIImagePickerController对于这两种
  • 使用 iPhone 中的地图视图读取当前位置名称

    我读取了当前位置的纬度和经度值 然后成功将该位置固定在 iPhone 中 现在我想使用这个纬度和经度值读取该地名 我使用以下代码来读取查找当前位置 void mapView MKMapView mapView1 didUpdateUserL
  • 在 OS X 上创建和使用静态库

    好的 我正在尝试创建一个 Cocoa 库 静态 并使用 但我不断收到错误 我创建了一个超基本的静态库 TSXLib 其中仅包含一个额外的类 import
  • 覆盖层不与 UITableView 一起滚动 - iOS

    我有一个 UITableView 类 它使用以下方法在转到下一个屏幕时调用加载覆盖 问题是这个加载屏幕不随列表滚动 所以如果你滚动一点并单击某些东西 加载屏幕不会显示 因为它位于顶部 如何让加载屏幕始终保持在 UITableView 的顶部
  • 在 XCode 中链接静态 ObjC 库的过程

    我正在尝试链接到静态库 但不断收到链接器错误 我发现了一些发布示例的网站 但我无法看到我做错了什么 首先 我创建一个链接到我的库的项目 添加 gt 现有文件找到我的 xcodeproj 文件选择 将项目复制到目标组文件夹 选择我的宿主项目作
  • 在 Objective C 的类方法中引用类本身

    我希望我没有跳过 ObjC 手册中的这一部分 但是是否可以从类的一个类方法中引用该类 就像在 PHP 中一样 您将使用 this 来引用当前实例 而 self 引用实例的类 this 的 ObjC 等价物将是 self 那么 PHP 的 s
  • 推送动画,没有阴影和停电

    我有一个简单的iOS NavigationController基于应用程序 二UICollectionViews 相继 如果元素打开 第一个合集 被点击时 第二集 将被打开 非常简单 重要的提示 Both UICollectionViews
  • insertNewObjectForEntityForName:

    我使用 Xcode xcdatamodel 文件编辑器设置了一个实体 我创建了一个名为 Person 的实体 添加了一些属性 然后生成了一个 m 文件来表示它 一切都很好 现在 当我去编写一行代码时 例如 Person person Per
  • 如何将 ios7 通用应用程序升级到基于 Xcode 6 的通用故事板应用程序?

    我目前有一个基于 xcode 5 ios 7 的通用应用程序 因此有两个故事板 我正在考虑将其更新到 ios 8 有没有办法 最佳方法将两个故事板迁移到通用的单个故事板 我在 xcode 6 中看不到转换选项 None
  • 水平 UICollectionView 单行布局

    我正在尝试使用以下命令设置简单的水平布局UICollectionView 兜圈子却没有达到预期的结果 所以任何指针或例子将不胜感激 我粘贴经常更改的代码但没有成功可能没什么意义 该图像显示两行 第一行是单个项目 尺寸正确并且在中心正确对齐
  • ABAddressBookCopyArrayOfAllPeople 中缺少联系人

    我试图从我的应用程序中的地址簿中查找电话号码 但很惊讶没有找到它 问题是 我已经在我的应用程序访问的控制台中打印了地址簿的所有号码 奇怪的是 有些联系人丢失了 我正在将输出与我的地址簿进行比较 虽然数量很少 但仍然如此 这就是我访问地址簿的
  • 如何删除 UITableView 中的缩进?

    首先 我对此很陌生 我很可能忘记了一些非常简单的事情 问题 我正在制作一个应用程序 在 a 中显示来自 imgur com 的随机图像tableView 由于某种原因 所有单元格都会缩进少量 如下图所示 我摆弄了许多设置storyboard
  • 有角度的动态背景图片

    在 html 模板中 我有这种带有动态图像的样式 div style background none width 200px height 150px div 它适用于网络浏览器和 Android 浏览器 但是 使用 style 的动态背景
  • 诊断和仪器均缺少“僵尸”选项

    运行 Xcode 4 0 2 Zombie 选项丢失 其他 SO 帖子建议找到它的两个地方 Product gt Run looks like this Product gt Profile looks like this 奇怪的是 我之前

随机推荐