开发iPad应用程序与iPhone有一点小差别,就是iPad支持d出框。这个示例展示如何在UIPopoverController上显示一个UIPickerVIEw,当然你可以显示任何的UIVIEw到UIPopover上面。原理就是构建一个UIVIEwController,然后将这个UIVIEwController加在UIPopoverController上,最近显示UIPopoverController,即显示出我们的UIVIEwController的内容。
首先,要我们的controller支持UIPickerVIEwDelegate,UIPopoverControllerDelegate协议,
@interface myVIEwController : UIVIEwController<UIPickerVIEwDelegate,UIPopoverControllerDelegate>
然后开始显示uipickervIEw
- (voID)showPickerInPopover:(CGRect)rect { UIVIEwController *sortVIEwController = [[UIVIEwController alloc] init]; UIVIEw *theVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0, 0, 320, 216)]; UIPickerVIEw *thePicker = [[UIPickerVIEw alloc] initWithFrame:CGRectMake(0, 216)]; thePicker.delegate = self; thePicker.dataSource = self; thePicker.showsSelectionIndicator = YES; [theVIEw addSubvIEw:thePicker]; sortVIEwController.vIEw = theVIEw; [theVIEw release]; popVIEwController = [[UIPopoverController alloc] initWithContentVIEwController:sortVIEwController]; [popVIEwController setPopoverContentSize:CGSizeMake(320, 216) animated:NO]; [popVIEwController presentPopoverFromrect:rect inVIEw:self.vIEw permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; popVIEwController.delegate = self; ; [sortVIEwController release]; }
注意内存管理,要释放UIPopoverController:
voID)popoverControllerDIDdismisspopover:(UIPopoverController *)popoverController { [popVIEwController release]; }还有实现UIPickerDelegate
voID)pickerVIEw:(UIPickerVIEw *)pickerVIEw dIDSelectRow: (NSInteger)row inComponent:(NSInteger)component { // Handle the selection } // tell the picker how many rows are available for a given component - (NSInteger)pickerVIEw:(UIPickerVIEw *)pickerVIEw numberOfRowsInComponent:(NSInteger)component { NSUInteger numRows = 5; return numRows; } // tell the picker how many components it will have - (NSInteger)numberOfComponentsInPickerVIEw:(UIPickerVIEw *)pickerVIEw { return 1; } // tell the picker the Title for a given component - (Nsstring *)pickerVIEw:(UIPickerVIEw *)pickerVIEw TitleForRow:(NSInteger)row forComponent:(NSInteger)component { Nsstring *Title; Title = [@"" stringByAppendingFormat:@"%d",row]; return Title; } // tell the picker the wIDth of each row for a given component - (CGfloat)pickerVIEw:(UIPickerVIEw *)pickerVIEw wIDthForComponent:(NSInteger)component { int sectionWIDth = 300; return sectionWIDth; }
UIPickerVIEw里的内容自行修改。 总结
以上是内存溢出为你收集整理的UIPickerView在UIPopoverController中正确显示方法全部内容,希望文章能够帮你解决UIPickerView在UIPopoverController中正确显示方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)