UIPickerView 쇼에 "완료", "취소"버튼을 만들 수있는 방법을 찾고있었습니다.
주위를 인터넷 검색 좋은 게시물을 발견, 그들 모두가 관련 UIActionSheet했다.UIActionSheet가 중간에 나타납니다
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)];
응용 훌륭한 시작하고 :
그래서 나는
컨테이너가 UIView
actionSheet가 UIActinSheet
pickerView는이 UIPickerView
있는 viewDidLoad 에있다라고했다 모든 것이 멋지다. 줄에 있으십시오 : [actionSheet showInView:container];
지금, 내가 ActionSheet를 닫으려고 할 때, 그것은 잘 작동합니다! 에서
는을 dismissActionSheet :
[actionSheet dismissWithClickedButtonIndex:1 animated:NO];
문제, 어떻게 다시 표시하게 할 수있다?
내가 사용하는 경우 :
[actionSheet showInView:container];
나는 단지 버튼을 사용하여 바닥에서 따기 도구 모음을 얻고 그게입니다. 전체 PickerView가 바닥에 있으며 볼 수 없습니다.
내가 뭘 잘못하고 있니?
전체 스키마가 변경되었습니다. 사용 된 사용자 지정 UIView 및 실질적으로 수동으로 UIActionSheet가 나를 위해 무엇을 할 것인지를 예상해야했습니다. 나쁘지 않아. 기본적으로 뒤쪽의 UIButton 및 보조 애니메이션 메서드가있는 UIPickerView 및 UIToolBar의 위치가 변경됩니다. – Ted