2012-11-06 3 views
1

나는 actionSheet라고하는 UIActionSheet의 인스턴스 변수 인 클래스 변수를 가지고 있습니다. 나는 UISegmentedControl의 인스턴스뿐만 아니라 UIPickerView의 인스턴스를 추가합니다. 비록 "완료"버튼 (UISegmentedControl의 인스턴스)을 탭할지라도, 클래스 메소드 dismissActionSheet는 호출되지 않습니다. 누구든지 나를 도울 수 있습니까?UIButton addTarget 메서드 ... 작동하지 않습니까?

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 

-(IBAction)chooseTopicButtonPressed{ 


    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                  delegate:nil 
                cancelButtonTitle:nil 
               destructiveButtonTitle:nil 
                otherButtonTitles:nil]; 

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

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

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

    [actionSheet addSubview:pickerView]; 


    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]]; 
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(10, 6, 300, 30); 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blueColor]; 
    [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventTouchUpInside]; 


    //dismissActionSheet NOT BEING CALLED FOR SOME REASON!!! 

    [actionSheet addSubview:closeButton]; 

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; 

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


-(void)dismissActionSheet{ 
    NSLog(@"dismissActionSheet called"); 
    [actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 

} 
+3

합니다. 'UIActionSheet'는 버튼 메뉴를 보여줍니다. 'UISegmentedControl'은 실제로 일반적인 경우 버튼으로 사용되지 않습니다. 요즘, 애플은'UIActionSheet'의 구현을 업데이트 할 것이고 그것을 잘못 사용하는 사람들은 많은 이슈를 가질 것입니다. 'UISegmentedControl' 대신 실제 UIButton을 사용하거나'UIActionSheet'의 버튼 중 하나를 사용해보십시오. – rmaddy

답변

2

다음과 같이 @selector이 있어야 할 수 있도록 인수가없는 dismissActionSheet 방법 : 컨트롤의 오용의 많은입니다

[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventTouchUpInside]; 
관련 문제