尝试修复此错误:找不到映射的图像 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 的相关文章

  • 是否可以对 UILabel 的文本颜色变化进行动画处理? [复制]

    这个问题在这里已经有答案了 UIView animateWithDuration 5 animations myLabel textColor UIColor redColor 标签文本颜色立即改变 Try this UIView tran
  • 在两个可移动 uiview 之间画线

    我有一个带有节点的 滚动视图 UIViews 可以拖动 我正在尝试在选定的之间绘制边缘UIViews使用 calayer 但我不知道当视图位置发生变化时如何重新绘制线条 In my viewControllerI 类在节点数组中添加第一个和
  • 在后台运行 URL 请求

    我想在一定的时间间隔内发出 url 请求 例如 每 10 分钟应用程序应该发出一次 url 调用并获取一些 json 数据 应用程序在后台运行时应该能够执行此操作 这可以做到吗 如果是这样 这是否违反 Apple 服务条款 有什么限制吗 i
  • 如何将NSTextView的格式化内容转换为字符串

    我需要将 NSTextView 的内容从 Mac 应用程序传输到 iOS 应用程序 我使用 XML 作为传输文件格式 所以我需要将 NSTextView 的内容 文本 字体 颜色等 保存为字符串 有什么办法可以做到这一点吗 一种方法是存档
  • 应用程序仅启用纵向,但 UIImagePickerController 在 iOS6 中旋转

    请注意 下面的答案 不适用于 iOS6 所以我仍然需要答案 我的应用程序仅启用纵向模式 但是 如果我将 UIImagePickerController 作为子视图嵌入其中 并旋转设备 则顶部和底部栏将保持在同一位置 但 UIImagePic
  • 如何在没有 MFMessageComposeViewController 的情况下发送和接收短信?

    我想发送和接收短信而不显示MFMessageViewController从我的申请中 有人能告诉我这怎么可能吗 不可能 除非您使用第 3 方 api 发送 接收短信
  • iOS 开发:如何强制 UIWebView 加载 Facebook 的非移动版本?

    我正在深入研究 iOS 开发 当我尝试在 UIWebView 中加载特定的 Facebook 粉丝页面时 它会加载该网站的移动版本 该版本仅加载粉丝页面的墙 而不是我需要加载的特定选项卡 在我的应用程序的 iPad 版本中 UIWebVie
  • 如何删除以前的 ViewController

    我是一名学生 对编程还很陌生 我正在尝试在业余时间学习 Objective C Swift 我使用 spriteKit 和 swift 制作了一个游戏 有多个菜单 场景 我正在尝试从一个视图控制器转换到另一个视图控制器 为此 我使用了以下代
  • CIGaussianBlur 有时会改变图像方向

    在我的 iOS 应用程序中 我想在 UIImage 上应用一个滤镜 CIGaussianBlur 当它获得具有大高度的图像时 它会旋转图像 CIContext context CIContext contextWithOptions nil
  • 如何停止覆盖数据

    我正在尝试在我的 iOS 应用程序中保存一些数据 我使用以下代码 NSArray paths NSSearchPathForDirectoriesInDomains NSDocumentDirectory NSUserDomainMask
  • iOS:自动调整大小不适用于 UIImageView

    我正在制作一个非常简单的应用程序来学习 Objective C 和 Xcode 该应用程序有一个 UIButton 和一个 UIImageView 当用户点击按钮时 图像从右到左以对角线运动向下移动 当它到达屏幕中的某个点时 它会重新生成以
  • 将 iCloud 数据迁移到本地存储并阻止 iCloud 继续响应

    我即将在我的应用程序中完成 iCloud 和 Core Data 的实现 这是一款仅限 iOS 7 的应用程序 我在应用程序中为用户提供了一个选项 以 打开 或 关闭 的形式显示 使用 iCloud UISwitch 该应用程序启动时会询问
  • 检查包含 URL 的字符串“http://”

    我正在尝试检查用户输入的 URL 但我正在与一些错误和警告作斗争 BOOL textFieldShouldReturn UITextField textField check http NSString check textField te
  • 自定义 UISearchController 动画

    底线问题 如何覆盖取消属于 UISearchController 的 searchBar 的默认动画 标准搜索控制器行为 好的 我正在尝试为附加到 UISearchController 的 UISearchBar 变为活动状态时创建自定义动
  • Objective-C 属性的默认属性是什么?

    当您未在 Objective C 中列出任何属性时 属性的默认属性是什么 例如 如果我这样写 property float value 默认值是什么 比如它是只读的 它是否保留 等等 默认 隐式值为atomic readwrite and
  • 如何检测和处理UIWebView中的HTTP错误代码?

    我想在收到 HTTP 错误 404 等时通知用户 我怎样才能检测到这一点 我已经尝试过实施 void webView UIWebView webView didFailLoadWithError NSError error 但当我收到 40
  • iOS7状态栏和导航栏问题

    我正在将我的应用程序迁移到 iOS 7 为了处理状态栏问题 我添加了以下代码 if UIDevice currentDevice systemVersion floatValue gt 7 0f CGRect frame self navi
  • 为什么这段代码不能产生正确的输出? [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 给定一个字符串和一个数字 该函数将从
  • 如何从我的应用程序打开 ios Native dialer 应用程序

    我想打开本机拨号器应用程序并允许用户在那里输入电话号码 我想要这个的原因是因为在我的应用程序中 用户需要使用 USSD 代码才能拨打电话 但使用下面的代码没有任何反应 没有任何启动 NSString phoneNumber tel stri
  • 为什么 NSOrderedSet 不继承 NSSet?

    当然 有序集是集合的更具体的情况 那么为什么NSOrderedSet继承自NSObject而不是NSSet 我通过了界面NSSet你是对的 有序集似乎满足里氏替换原则 http en wikipedia org wiki Liskov su

随机推荐