我正在尋找一種方法使UIPickerView顯示「完成」,「取消」按鈕。
谷歌搜索我發現很好的帖子,他們都有涉及UIActionSheet。UIActionSheet出現中途
所以我做了
容器是UIView
actionSheet是UIActinSheet
pickerView是UIPickerView
在viewDidLoad中:
container = [[[UIView alloc] initWithFrame:CGRectMake(rect.origin.x,rect.origin.y, rect.size.width, rect.size.height)] autorelease];
[self.view addSubview:container];
actionSheet = [[UIActionSheet alloc] initWithTitle:@"myTitle"
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[[UIPickerView alloc] initWithFrame:pickerFrame]autorelease];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
UIToolbar *toolbar = [[[UIToolbar alloc] init] autorelease];
toolbar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
[items addObject:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismissActionSheet)] autorelease]];
[items addObject:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(goActionSheet)] autorelease]];
[items addObject:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(goActionSheet)] autorelease]];
[toolbar setItems:items animated:NO];
[actionSheet addSubview:toolbar];
[actionSheet addSubview:pickerView];
[actionSheet showInView:container];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
應用程序啓動時大,整個事情都表現得很好上線:[actionSheet showInView:container];
現在,當我試圖拒絕接受ActionSheet,它的偉大工程!
在dismissActionSheet:
[actionSheet dismissWithClickedButtonIndex:1 animated:NO];
的問題是,我怎麼讓它再次出現?
當我使用:
[actionSheet showInView:container];
我只得到了從工具欄使用按鈕底部採摘,就是這樣。整個PickerView在底部,我看不到它。
我在這裏做錯了什麼?
我改變了整個方案。 使用習慣UIView和幾乎不得不手動做什麼我期待的UIActionSheet爲我做。不錯。基本上是在後面的UIButton,並用輔助動畫方法改變UIPickerView和UIToolBar的位置。 – Ted 2012-07-13 15:20:20