开发者

Action sheet not being dismissed

开发者 https://www.devze.com 2023-01-29 16:17 出处:网络
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

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:开发者_StackOverflow社区reloadArray withRowAnimation:NO];
    [reloadArray release];


}

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


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";
    }
}


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

精彩评论

暂无评论...
验证码 换一张
取 消