1
我有一個類變量,是的UIActionSheet
一個實例,稱爲actionSheet。我添加了一個UIPickerView
的實例以及一個UISegmentedControl
的實例。雖然當我點擊「完成」按鈕(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];
}
這是一個很大的控制濫用。 'UIActionSheet'是爲了顯示一個按鈕菜單。 'UISegmentedControl'並不是真的用作一般情況下的按鈕。其中一天,蘋果可能會更新「UIActionSheet」的實現,並且每個使用錯誤方式的人都會遇到很多問題。嘗試使用真正的UIButton而不是'UISegmentedControl'或嘗試使用'UIActionSheet'中的某個按鈕。 – rmaddy