2011-04-20 9 views
11

uipicker를 uiaickheet에 표시하는 데이 코드를 사용했지만 close 버튼을 클릭하면보기에서 액션 시트를 제거하고 싶습니다. actionSheet 폼 뷰를 제거하는 코드는 무엇이되어야합니다.액션 시트를 닫는 방법

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
pickerView.showsSelectionIndicator = YES; 
pickerView.dataSource = self; 
pickerView.delegate = self; 

[actionSheet addSubview:pickerView]; 
[pickerView release]; 

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
closeButton.tintColor = [UIColor blackColor]; 
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; 
[actionSheet addSubview:closeButton]; 
[closeButton release]; 

[actionSheet showInView:self.view];//[UIApplication mainWindow]]; 

[actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 
return false; 
} 
+0

[actionsheet removeFromSuperview] ; 하지만 작동하지 않습니다. –

+0

http://stackoverflow.com/questions/1551587/how-to-dismiss-uiactionsheet-automatically –

답변

11

당신이 dismissWithClickedButtonIndex:animated:

+0

허, 이미 알아 냈어 : P – ttarik

+0

덕분에 좋은 도움을 주겠다. –

+0

스위프트는 어땠습니까? – dylan

4

조치 시트 범위 문제.

+0

어디에서 사용 했습니까? 나는 dismissActionSheet 메소드를 생성하려고 시도했지만, [actionSheet dismissWith ...]를 넣어 봤지만 작동하지 않는 것 같습니다. –

7

이 방법은 나를 위해 일 추가로 할 수있는 ActionSheet를 기각하기 만 [actionSheet dismissWithClickedButtonIndex:0 animated:YES];을 사용 : 내가 사용하고

-(void) dismissActionSheet:(id)sender { 
     UIActionSheet *actionSheet = (UIActionSheet *)[(UIView *)sender superview]; 
     [actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 
    } 
+0

내 보낸 사람은 하위보기로 작업 시트에 추가 된 UIToolBar에 추가 된 변경 가능한 배열에 추가되는 UIBarButtonItem입니다. Dismiss 방법에서 작업 시트에 어떻게 액세스합니까? – marciokoko