行动表未被驳回

发布于 2024-10-06 20:26:26 字数 2006 浏览 4 评论 0原文

我最近编写了一个类,它从表格单元格中呈现自定义 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];


}

感谢您花时间阅读这篇相当长的文章, 将要

I've recently written a class that presents a custom uiactionsheet from a tablecell, in this actionsheet is a pickerview and a toolbar. When the done button on the toolbar is pressed a notifcation is sent with the choosen pickerview value and the actionsheet is dismissed. Sometimes the actionsheet vanishes from the view when the done button is pressed however it appears that the modal property of that actionsheet remains as am unable to select anything on the view that appears. Moving to another tab and coming back seems to solve this. Does anyone have any ideas what could be causing this?

Below is the code I use to dismiss my actionsheet:

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

and the notification method that is called:

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


}

Thanks for taking the time to read this rather long post,
Will

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哎呦我呸! 2024-10-13 20:26:26

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

As far as i know, you should the actionSheet: clickedButtonAtIndex method..

-(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";
    }
}
画尸师 2024-10-13 20:26:26

我确实设法解决了这个问题,但感觉很像黑客,我使用

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

以下方法在代码中引入了延迟:

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

I did manage to solve this however it feels very much like a hack, I introduced a delay into the code using:

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

With dismissFromActionSheet being:

-(void)dismissFromActionSheet{
 [self dismissWithClickedButtonIndex:0 animated:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文