【问题标题】:Action sheet not being dismissed行动单未被驳回
【发布时间】:2010-12-10 10:28:28
【问题描述】:

我最近编写了一个类,它从一个表格单元中呈现一个自定义的 uiactionsheet,在这个 actionsheet 中是一个选择器视图和一个工具栏。当按下工具栏上的完成按钮时,将发送带有所选pickerview 值的通知,并且操作表被关闭。有时,当按下完成按钮时,动作表会从视图中消失,但该动作表的模态属性似乎仍然无法在出现的视图上选择任何内容。移动到另一个选项卡并返回似乎可以解决这个问题。有谁知道是什么原因造成的?

以下是我用来关闭操作表的代码:

-(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];


}

感谢您花时间阅读这篇相当长的帖子, 会

【问题讨论】:

  • -reloadRowsAtIndexPaths:withRowAnimation:的第二个参数不是BOOL;这是一个UITableViewRowAnimation 类型

标签: objective-c notifications reload uiactionsheet modalviewcontroller


【解决方案1】:

据我所知,你应该使用 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";
    }
}

【讨论】:

  • 感谢 stackr 的反馈,在这种情况下,我没有以这种方式使用操作表。我用它来托管一个pickerview而不是按钮,我添加的按钮是顶部的工具栏
【解决方案2】:

我确实设法解决了这个问题,但感觉很像黑客,我在代码中引入了延迟:

[self performSelector:@selector(dismissFromActionSheet) withObject:nil afterDelay:0.2];

dismissFromActionSheet 是:

-(void)dismissFromActionSheet{
 [self dismissWithClickedButtonIndex:0 animated:YES];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    相关资源
    最近更新 更多