日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

UIPopoverController的使用

發(fā)布時間:2024/9/20 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UIPopoverController的使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
UIPopoverController的使用2011-10-04 13:41

有些時候需要用到彈出窗口,這個時候UIPopoverController就有用武之地了,下面介紹一個使用UIPopoverController的示例,以供參考。實現(xiàn)效果如下:

為了實現(xiàn)這一效果并使用UIPopoverController,這里搞了兩個controller,具體定義如下。

//? Created by Chelsea Wang 4209898762 on 11-10-4.

//? Copyright 2011年?__MyCompanyName__. All rights reserved.

#import?<UIKit/UIKit.h>

@interface?UIActionSheetDemoViewController :?UIViewController<UIPopoverControllerDelegate>{

? ??UIPopoverController* _popover;

}

//? UIActionSheetDemoViewController.m

//? UIActionSheetDemo

//

//? Created by Chelsea Wang 4209898762 on 11-10-4.

//? Copyright 2011年?__MyCompanyName__. All rights reserved.

//

#import?"UIActionSheetDemoViewController.h"

#import?"popController.h"

@implementation?UIActionSheetDemoViewController

@synthesize?popover =?_popover;

- (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.

}

#pragma mark - View lifecycle

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad

{

? ? [super?viewDidLoad];

?? ?

? ??UISegmentedControl* settingView = [[UISegmentedControl?alloc]?initWithItems:[NSArrayarrayWithObjects:@"FootballCF",@"BasketballCF",nil]];

? ? [settingView?setSegmentedControlStyle:UISegmentedControlStyleBar];

? ? [settingView?setFrame:CGRectMake(500,?900,?160,?75)];

? ? [settingView?setNeedsLayout];

? ? [settingView?addTarget:self?action:@selector(segmentAction:)?forControlEvents:UIControlEventValueChanged];

? ? [self.view?addSubview:settingView];

? ? [settingView?release];

}

- (void)viewDidUnload

{

? ? [super?viewDidUnload];

? ??// Release any retained subviews of the main view.

? ??// e.g. self.myOutlet = nil;

?? ?

? ??if?(self.popover?!=?nil) {

? ? ? ? [self.popover?release];

? ? ? ??self.popover?=?nil;

? ? }

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

? ??// Return YES for supported orientations

? ??return?YES;

}

-(void)segmentAction:(UISegmentedControl*)seg{

? ??//清除已經(jīng)顯示的彈出窗口

? ??if?(self.popover.popoverVisible) {

? ? ? ? [self.popover?dismissPopoverAnimated:YES];

? ? }

? ??//初始化待顯示控制器

? ??popController* controller = [[popController?alloc]?init];

? ??//設置待顯示控制器的范圍

? ? [controller.view?setFrame:CGRectMake(550,?490,?350,?450)];

? ??//設置待顯示控制器視圖的尺寸

? ? controller.contentSizeForViewInPopover?=?CGSizeMake(350,?450);

? ??//初始化彈出窗口

? ??UIPopoverController* pop = [[UIPopoverController?alloc]?initWithContentViewController:controller];

? ? controller.popover?= pop;

? ??self.popover?= pop;

? ??self.popover.delegate?=?self;

? ??//設置彈出窗口尺寸

? ??self.popover.popoverContentSize?=?CGSizeMake(350,?450);

?? ?

? ??//顯示,其中坐標為箭頭的坐標以及尺寸

? ? [self.popover?presentPopoverFromRect:CGRectMake(550,?890,?10,?10)?inView:self.viewpermittedArrowDirections:UIPopoverArrowDirectionDown?animated:NO];

?? ?

? ? [controller?release];

? ? [pop?release];

?? ?

? ??//[self.popover dismissPopoverAnimated:YES];

}

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

? ??NSLog(@"popover dismiss");

}

@end

//

//? popController.h

//? UIActionSheetDemo

//

//? Created by Chelsea Wang 4209898762 on 11-10-4.

//? Copyright 2011年?__MyCompanyName__. All rights reserved.

//

#import?<UIKit/UIKit.h>

@interface?popController :?UIViewController<UIPickerViewDelegate,UIPickerViewDataSource>{

? ??UIPopoverController* _popover;

? ??BOOL?isChelsea;

}

@property(nonatomic,retain)UIPopoverController* popover;

@end

//? popController.m

//? UIActionSheetDemo

//

//? Created by Chelsea Wang 4209898762 on 11-10-4.

//? Copyright 2011年?__MyCompanyName__. All rights reserved.

//

#import?"popController.h"

@implementation?popController

@synthesize?popover =?_popover;

//定義選項顯示內容

const?char* chelsea[12] = {"博阿斯","切赫","阿什利科爾","特里","路易斯","伊萬諾維奇","蘭帕德","拉米雷斯","梅來雷斯","阿內爾卡","德羅巴","托雷斯"};

- (id)initWithNibName:(NSString?*)nibNameOrNil bundle:(NSBundle?*)nibBundleOrNil

{

? ??self?= [super?initWithNibName:nibNameOrNil?bundle:nibBundleOrNil];

? ??if?(self) {

? ? ? ??// Custom initialization

?? ? ? ?

?? ? ? ?

? ? }

? ??return?self;

}

- (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.

}

#pragma mark - View lifecycle

- (void)viewDidLoad

{

? ? [super?viewDidLoad];

? ??// Do any additional setup after loading the view from its nib.

?? ?

? ??isChelsea?=?NO;

?? ?

? ??//添加完成按鈕

? ??UISegmentedControl* doneButton = [[UISegmentedControl?alloc]?initWithItems:[NSArrayarrayWithObjects:@"Done",?nil]];

? ? [doneButton?setSegmentedControlStyle:UISegmentedControlStyleBar];

? ? [doneButton?setFrame:CGRectMake(self.view.bounds.origin.x+self.view.bounds.size.width-100,self.view.bounds.origin.y+5,?75,?50)];

? ? [doneButton?addTarget:self?action:@selector(segmentAction:)?forControlEvents:UIControlEventValueChanged];

? ? [self.view?addSubview:doneButton];

? ? [doneButton?release];

? ??//添加選擇項

? ??UISegmentedControl* clubSeg = [[UISegmentedControl?alloc]?initWithItems:[NSArrayarrayWithObjects:@"Chelsea",@"AC Milan",@"Livupoor",@"Asenal",nil]];

? ? [clubSeg?setSegmentedControlStyle:UISegmentedControlStyleBar];

? ? [clubSeg?setFrame:CGRectMake(self.view.bounds.origin.x,self.view.bounds.origin.y+75,self.view.bounds.size.width,50)];

? ? [clubSeg?addTarget:self?action:@selector(chooseClub:)?forControlEvents:UIControlEventValueChanged];

? ? [self.view?addSubview:clubSeg];

? ? [clubSeg?release];

?? ?

? ??//添加選擇列表

? ??UIPickerView* picker = [[UIPickerView?alloc]?initWithFrame:CGRectMake(self.view.bounds.origin.x,self.view.bounds.origin.y+150,?self.view.bounds.size.width,self.view.bounds.size.height)];

? ? [picker?setBounds:CGRectMake(self.view.bounds.origin.x,?self.view.bounds.origin.y+75,self.view.bounds.size.width,self.view.bounds.size.height)];

? ? picker.delegate?=?self;

? ? picker.dataSource?=?self;

? ? picker.showsSelectionIndicator?=?YES;

? ? [self.view?addSubview:picker];

? ? [picker?setTag:101];

? ? [picker?release];

?? ?

?? ?

}

- (void)viewDidUnload

{

? ? [super?viewDidUnload];

? ??// Release any retained subviews of the main view.

? ??// e.g. self.myOutlet = nil;

? ??if?(self.popover?!=?nil) {

? ? ? ? [self.popover?release];

? ? ? ??self.popover?=?nil;

? ? }

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

? ??// Return YES for supported orientations

? ??return?YES;

}

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

? ??return?1;

}

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

? ??return?12;

}

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

? ??if?(isChelsea) {

? ? ? ??return?[NSString?stringWithCString:chelsea[row]?encoding:NSUTF8StringEncoding];

? ? }else{

? ? ? ??return?[NSString?stringWithFormat:@"chelsea_%d",arc4random()%12];

? ? ? ? ;

? ? }

?? ?

}

-(void)segmentAction:(UISegmentedControl*)seg{

? ? [self.view?removeFromSuperview];

? ? [self.popover?dismissPopoverAnimated:YES];

}

-(void)chooseClub:(UISegmentedControl*)seg{

? ??NSInteger?index = seg.selectedSegmentIndex;

? ??UIPickerView* picker = (UIPickerView*)[self.view?viewWithTag:101];

? ??switch?(index) {

? ? ? ??case?0:{

? ? ? ? ? ??NSLog(@"you choose Chelsea");

? ? ? ? ? ??isChelsea?=?YES;

? ? ? ? ? ? [picker?reloadAllComponents];

? ? ? ? ? ??break;

? ? ? ? }

? ? ? ??case?1:

? ? ? ? ? ??NSLog(@"you choose AC Milan");

? ? ? ? ? ??isChelsea?=?NO;

? ? ? ? ? ? [picker?reloadAllComponents];

? ? ? ??case?2:

? ? ? ? ? ??NSLog(@"you choose Livopoor");

? ? ? ? ? ??isChelsea?=?NO;

? ? ? ? ? ? [picker?reloadAllComponents];

? ? ? ??case?3:

? ? ? ? ? ??NSLog(@"you choose Asenal");

? ? ? ? ? ??isChelsea?=?NO;

? ? ? ? ? ? [picker?reloadAllComponents];

? ? ? ??default:

? ? ? ? ? ??break;

? ? }

}

@end

@property(nonatomic,retain)UIPopoverController* popover;

@end

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的UIPopoverController的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。