我最近编写了一个从表格单元格中显示自定义uiactionsheet的类,在此操作表中是一个选择器视图和一个工具栏。当按下工具栏上的完成按钮时,将发送带有选择的选择器视图值的通知,并且动作表将被取消。有时,当按下完成按钮时,操作表将从视图中消失,但看起来该操作表的模态属性仍然无法在显示的视图上选择任何内容。转移到另一个选项卡并回来似乎解决了这个问题。有没有人有任何想法可能导致这个?
以下是我用来解雇我的动作表的代码:
-(void)doneButtonPressed:(id)sender{
if ([[self viewWithTag:1] isKindOfClass:[PickerView class]]) {
PickerView *picker = (PickerView *)[self viewWithTag:1];
if (picker.selectedRow == nil) {
[picker populateSelectRowForRow:0 andComponent:0];
}
NSNotification *note = [NSNotification notificationWithName:@"doneButtonPressed" object:self.indexPath userInfo:picker.selectedRow];
[[NSNotificationCenter defaultCenter] postNotification:note];
}else {
DatePickerView *picker = (DatePickerView *)[self viewWithTag:1];
NSDictionary *extraInfo = [[NSDictionary alloc] initWithObjects:[[NSArray alloc] initWithObjects:[self formatDateToString:[picker date]], nil] forKeys:[[NSArray alloc] initWithObjects:@"value", nil]];
NSNotification *note = [NSNotification notificationWithName:@"doneButtonPressed" object:self.indexPath userInfo:extraInfo];
[[NSNotificationCenter defaultCenter] postNotification:note];
}
[self dismissWithClickedButtonIndex:0 animated:YES];
}
和调用的通知方法:
-(void)pickerUpdate:(NSNotification *)note{
NSIndexPath *indexPath = [note object];
NSDictionary *extraInfo = [note userInfo];
NSDictionary *dict = [[tableController.sectionAndFields objectAtIndex:indexPath.section] objectAtIndex:(indexPath.row + kHeaderAndFooterOffset)];
[tableController.formDetails setObject:[extraInfo objectForKey:@"value"] forKey:[dict objectForKey:@"key"]];
NSArray *reloadArray = [[NSArray alloc] initWithObjects:indexPath, nil];
[indexPath release];
[self.tv reloadRowsAtIndexPaths:reloadArray withRowAnimation:NO];
[reloadArray release];
}
感谢您花时间阅读这篇相当长的帖子, 将
答案 0 :(得分:0)
据我所知,你应该使用actionSheet:clickedButtonAtIndex方法..
-(IBAction)showActionSheet:(id)sender {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:@"Destructive Button" otherButtonTitles:@"Other Button 1", @"Other Button 2", nil];
sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[sheet showInView:self.view];
[sheet release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
self.label.text = @"Destructive Button Clicked";
} else if (buttonIndex == 1) {
self.label.text = @"Other Button 1 Clicked";
} else if (buttonIndex == 2) {
self.label.text = @"Other Button 2 Clicked";
} else if (buttonIndex == 3) {
self.label.text = @"Cancel Button Clicked";
}
}
答案 1 :(得分:0)
我确实设法解决了这个问题,但感觉非常像黑客,我在代码中引入了延迟:
[self performSelector:@selector(dismissFromActionSheet) withObject:nil afterDelay:0.2];
dismissFromActionSheet为:
-(void)dismissFromActionSheet{
[self dismissWithClickedButtonIndex:0 animated:YES];
}