プログラムでuiPickerViewを作成し、インターフェイスビルダーを使用せずにビューに追加しようとしています。私は間違っていませんが、私はIBが好きですが、私がこのようにしたい理由は、UIPopoverViewControllerと様々な異なるサブビューを使用してポップアップメニューを生成するためにすばやくプラグインできるオブジェクトを作成しようとしているからですuiPickerViewなど)をポップアップのメニューとして使用します。私はすでにIBでメニューを構築し、そのViewControllerでポップアップを初期化することでこの作業を行いました。このエラーを修正しようとしました:マップされたイメージを見つけることができませんでしたUIPickerViewFrameLeft-162-Popover.png
私は、以下の関連するコードを入力した、これは私がそれを実行したときに私が得る2つのエラーです: - 「マッピングされた画像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とdelegateメソッドを設定する方法についてのチュートリアルに従っていますが、ここで確認したい場合はうまくいきます。
#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 {
}